I'm trying to visualize automatically (without user interaction) an image saved in C:\Myfolder\image.jpg in a UWP app. I know that this is a hot topic and UWP app can access only some "parts" of the filesystem but I also read that there are different solutions to overcome this problem like this
Trying this:
mainpage.cs
BitmapImage bitmap = new BitmapImage();
StorageFolder folder = await StorageFolder.GetFolderFromPathAsync(@"C:\MyFolder");
StorageFile file = await folder.GetFileAsync("image.jpg");
using (var stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read))
{
bitmap.SetSource(stream);
image0.Source = bitmap;
}
adding also this lines in appxmanifest:
<Applications>
<Application Id="App" Executable="$targetnametoken$.exe" EntryPoint="App">
<Extensions>
<uap:Extension Category="windows.fileTypeAssociation">
<uap:FileTypeAssociation Name="jpegfiles">
<uap:SupportedFileTypes>
<uap:FileType>.jpg</uap:FileType>
</uap:SupportedFileTypes>
</uap:FileTypeAssociation>
</uap:Extension>
</Extensions>
</Application>
</Applications>
<Capabilities>
<Capability Name="internetClient" />
<Capability Name="privateNetworkClientServer" />
<Capability Name="internetClientServer" />
<uap:Capability Name="enterpriseAuthentication" />
<uap4:Capability Name="userDataTasks" />
<DeviceCapability Name="microphone" />
</Capabilities>
Unfortunately, I'm obtaining always an error like: System.UnauthorizedAccessException: 'Access is denied.
I also tried to wirte the direct path of the image inside the Image object something like:
image0.Source = new BitmapImage(new Uri(@"C:\Myfolder\image.jpg"));
and in this case the app starts but it does not show anything.
Maybe I missed something or I do not understand how to set File access permissions.