In a chalktalk yesterday, I demo-ed a modified PhotoStore application (you may have seen this demo at last year’s PDC or played with it in the Hands on Labs).
In this version, you can display images bundled with the app as well as those located in your “My Pictures” directory. This works fine as standalone app because it runs in full trust. However, the sandboxed XBAP does NOT have FileIOPermission, and so fails with a SecurityException.
To make both XBAP & Standalone work with the same code base, I demoed the compile switching, runtime switching, and XAML switching tips I wrote about last week.
You can get code here. Or just run the xbap on RC1.
Note: this app uses my VS Flexible Application template.
Great session! Thanks for making the code available so soon.
Thanks for your great article.
But I want to know if I want to create xbap app which have to access local files, is there any other way to do that, such as after user permit or use some special mechanism?
access local files is critical, such as upload files, save files or others.
Is there any possible or indirect way to do that?
Thanks you very much 😀
Have a nice day
Yes, there are a few ways to get access to local files.
1. Show the user an OpenFileDialog (http://windowssdk.msdn.microsoft.com/en-us/library/microsoft.win32.openfiledialog.aspx). In the sandbox, this gives you a file stream as well as the SafeFileName (does not include path).
2. Trigger the browser download dialog on a file by setting the Content-Disposition header to “attachment” on the server.
Hope this helps!
Some more interesting stuffs with XBAP:
1. Valil Chess:
http://www.valil.com/winfx/RTM/Chess/XBAP/Valil.Chess.WinFX.xbap
2. Online Word Processing:
http://www.o2obox.com/office/WordXBAP.xbap