My understanding is that when I set SL5 to run OOB and elevated trust that I should have wide open access to any directory/file on the local system. If an external system places png image files into the user's c:\images folder, how can I load the various png files into a XAML Image element?
This line works:
image.UriSource = new Uri(value as string);
if I set value to a string like "http://blah.com/image1.png"
But fails if I try to set it to:
ImageUrl = new Uri(@"C:\images\image3.png")
which gets resolved to something like "file:///C:....." when it hits the
image.UriSource = new Uri(value as string);
line.
How do I display png files in SL5 from any local path on the system running the OOB elevated app?
Answer: 1
Something like this should work provided that you have elevated permissions set correctly
var bmp = new BitmapImage(); var stream = new FileStream(@"c:\dir\folder\image.png", FileMode.Open); bmp.SetSource(stream); stream.Close();
If you need to use a uri, this should work:
var bmp = new BitmapImage(); var uri = new Uri("c:/dir/folder/image.png"); bmp.UriSource = uri;
Note that the paths are different. The uri path requires forward slashes to be used.
You can then set the source of your image control to the bmp
image.Source = bmp;
If you're getting a 'File Operation not permitted' exception you need to double check that elevated permissions is checked in your out of browser settings
Project -> Properties -> 'Out of browser settings'
Check 'Require elevated trust...'
by : wdavohttp://stackoverflow.com/users/807836
No comments:
Post a Comment
Send us your comment related to the topic mentioned on the blog