0

I am writing an app that parses MD (Markdown) files, but I cannot seem to get images to work properly. Let's say that the file specifies a relative image:

![My image](../image.jpg)

I am telling UWP to use the following URI for the file: file:////, which results in file:///c:/somewhere/data/../image.jpg. But nothing shows up, and I do not get an exception or anything indicating that I do not have access to the file system, though I am suspecting that I do not.

Is there anything I can do to get images to load in this way?

This is how I intend to use the image:

                else if (line.StartsWith("!"))
                {
                    var s = line.IndexOf("(") + 1;
                    var n = line.IndexOf(")") - s;
                    var imagePath = line.Substring(s, n);

                    Uri uri;

                    if (!imagePath.Contains(Uri.UriSchemeHttp) && !imagePath.ToString().Contains(Uri.UriSchemeHttps))
                    {
                        // Local image, relative to the document.
                        uri = new Uri(this.fileUri + imagePath);
                    }
                    else
                    {
                        uri = new Uri(imagePath);
                    }

                    var bitmap = new BitmapImage
                    {
                        UriSource = uri
                    };

                    parent.Children.Add(new Image()
                    {
                        Source = bitmap,
                        Stretch = Stretch.None,
                        HorizontalAlignment = HorizontalAlignment.Left
                    });
                }
Christoffer
  • 545
  • 1
  • 5
  • 19
  • Does this answer your question? [UWP UnauthorizedException](https://stackoverflow.com/questions/32538658/uwp-unauthorizedexception) – Clemens Aug 27 '20 at 14:56
  • UWP apps are not allowed to access arbitrary folders in the local file system. – Clemens Aug 27 '20 at 14:56
  • Well, that thread leads to a broken link, so unfortunately it is not helpful :( – Christoffer Aug 27 '20 at 19:44
  • See also https://learn.microsoft.com/en-us/windows/uwp/packaging/app-capability-declarations and search StackOverflow for e.g. "uwp file access". – Clemens Aug 27 '20 at 20:20
  • I found out about broadFileSystemAccess capabiity, but it did not seem to do anything. The thing is that I am trying to read a picture relative to the MD file and then using it as an Image source. I have modified my initial post to show the code for how I use this. – Christoffer Aug 28 '20 at 08:57
  • Did you enable the capability in settings? – Peter Torr - MSFT Aug 29 '20 at 16:53
  • I did, after finding out about that Privacy setting. All is working now. – Christoffer Aug 29 '20 at 16:57

0 Answers0