views:

183

answers:

2

I have an XBAP app, which shows some pictures, and my users would like to save some of them to disk. But my XBAP app runs in the partial trust mode, so it can't initiate SaveFileDialog, not to mention it can't access the File System.

What's would be the Stack Overflow recommended way to save a pic to disk in this case?

A: 

I found a solution to my problem and I'm going to put this answer as a community wiki.

As expected, I wasn't able to access file system, show SaveFileDialog or save the image to the clipboard due to the partial-trust security limitations.

So, I've created an .ashx handler on the site, from which my XBAP application is deployed, which receives a certain image id in the URL string, queries the image from the DB, and returns the image (context.WriteBinary) under the proper content header "image/jpeg".

In my XBAP, instead of the Image control I've put the WebBrowser control, provided with the proper URI (you might need a trick to bind the Source property). You can only specify an URI that is pointing to the site of origin of your XBAP app. It can be an absolute path, or it can use the special syntax including pack://siteoforigin:,,

Voila, now the picture supports the standard browser context menu with "Save...", "Set as background" and all the other useful elements :-)

Yacoder
A: 

Yacoder, thanks for follow up on you own question. I have a similar problem. Could you elaborate more on how you used the packed uri.

webbrowser.Source = new Uri("pack://siteoforigin:,,,/MyWebHandler.ashx/?file=test.jpg"); How do you add params to the url in the uri? I get an exception: "Part URI cannot end with a forward slash."

Also debugging (getting the XBAP and ASHX to same site), do you deploy the ASHX handler to the same dir as the XBAP is running from, like myproject\bin\Debug\'?

Thanks, Klaus

Sirius
I guess it should be like "MyWebHandler.ashx?file=test.jpg", i.e. without a slash
Yacoder