In Browser Silverlight Application - Client Side File/Directory access - silverlight

When building a Silverlight 4 application is it possible to get a directory listing from an in browser application?
It seems the SaveFileDialog does not have the capability to set the file name of the file being saved, so I thought that I could create my own user control, however it seems that is not possible as I can't get a directory listing in an in-browser application.
I realize that certain well known directories are accessible from Silverlight 4 in out-of-browser application, but that doesn't help an in-browser application.

In-browser Silverlight apps are constrained by the sandbox, so from a file I/O perspective it's not much different from SL3 in the sense that you really have no access to the file system outside of Isolated Storage. Of course, a user can specify whatever directory they want to save a file in but you cannot specify it for the user - it's 100% the user's call on where a file is stored, and client-side file storage outside of Isolate Storage must be user-initiated.

Related

Read content of folder without AIR in AS3 (no flash.filesystem)

I'm working on a project and I need to dynamically check what is in onhe of my folder. The idea is that I have the id of a quest, and there is a folder name after that id. My code needs to check if this folder exist AND if there is something in it. After that, it show all the picture inside that folder. The goal is that I will just have to add picture in a folder to have them appear in my game.
I tried to find a way to check the content of my folder, but everyone say that I need flash.filesystem, BUT it means that I need to use AIR. AIR does NOT work in FireFox or any other browser.
Here is the website that make me understood that:
http://www.experts-exchange.com/Software/Photos_Graphics/Web_Graphics/Macromedia_Flash/Q_26118847.html
How can I explore the content of my folders then?
There is absolutely no way to explore the local file system without user interaction in Flash. If you want to do it, you must make an AIR application, which is not browser-based. This is a security feature that is imposed by each browser (you can't do it in JS either) and implemented identically by Adobe.
You can use FileReference to allow a user to select file(s) for Flash to have access to or save a file, but that is the most interaction with the filesystem that will be possible without opening AIR (which is also not limitless. Even with AIR, you won't have full access to the file system and will be locked out of certain directories and prevented from doing certain things)
If the folders are on your server you'll need to rely on a server side script to do the job and pass the result to your app.
If you mean folders on client side computer it's not gonna be possible for security reason.

Is it possible to display IsolatedStorage path in silverlight5

Could you please tell me is there any way to display Isolated-storage path using In-browser type silverlight5 application.
The full path to the isolated storage is normally not programmatically retrievable, at least not in Silverlight.
It is not possible to access m_AppFilesPath member in the IsolatedStorageFile instance through reflection, since the field is private. If you try to do this, you are likely to receive FieldAccessException.
If you are looking for the file system location of the isolated storage files and directories, please read this SO answer.
If you want to find out the file paths relative to the isolated storage root when running your application, AFAIK there is only the GetFileNames methods in the IsolatedStorageFile class, preferably in combination with GetDirectoryNames.
It is in principle possible to request the relative file path of a specific file as well by accessing the Name property of the IsolatedStorageFileStream object, however this property is only available in trusted applications.
Would it be possible to get the isolated storage location in a WPF app? I'm having problems with a customer using VDI (Virtual Desktop Infrastructure). Sometimes the isolated storeage will work and sometimes it doesn't. Seems like it's random and I want to try to debug this.
They're using a roaming user account.

In a local WPF Web Browser Application how do I write to a file? Sandbox doesn't allow?

So I have a local WPF web browser application and I need it to write to a text file. However I always get the an exception of type System.Reflection.TargetInvocationException. I don't get any more information but I'm pretty sure it is because it is being run from a web browser (security etc.).
The code I am using works in a regular windows form application etc. it is the usual:
StreamWriter sw;
sw = File.CreateText("c:\\myTextFile.txt");
sw.WriteLine("First line");
sw.Close();
So, is there a workaround for this?
Many thanks,
Thomas
You could try running in Full Trust mode.
WPF in a browser is going to default to partial trust. You can change that in the Security tab in Project Properties (subject, of course, to it being installed by a trusted user).
The issue is not WPF security problems. The issue is an operating system security feature in play: you can't write to the root of the C: drive without admin privs. Not only would your app need to be in WPF Full Trust mode, but you'd need to grant your app administrative priveledges on Vista and Windows 7 and beyond.
All that said, you should be able to write to files in non-protected paths. For example, you could write to a temporary file as returned by Path.GetTempFilePath(). However, it's likely your WPF browser app will still have to be running in full trust to write to disk at all.
See this page, describing Partial Trust security considerations. If you need to store the file for your own application's use, consider using Isolated Storage. If you want to allow the user to save a file to disk, you can use SaveFileDialog.OpenFile to allow the user to choose a path and confirm saving the file.

Can two Silverlight applications share IsolatedStorage on one machine?

What identifies an silverlight application and when can two silverlight applications share IsolatedStorage if at all, i.e.:
if I want to have two Silverlight applications share IsolatedStorage space, is this possible? What kind of "application id" do I need to give to do this?
if I don't want two Silverlight applications to share IsolatedStorage, how do I prevent this? Do I need to do this?
For instance, I've noticed when I develop a Silverlight application, I can press F5, in the application save to Isolated Storage, stop the application, press F5 again, and it reads from the same IsolatedStorage. (I would think that a new compilation would cause it to use new IsolatedStorage.)
However, when I then copy the .xap and .html files to another directory and open the .html file, it does NOT share the IsolatedStorage with the application I was developing. What changed?
What is going on behind the scenes here so I know when IsolatedStorage is shared and when it isn't?
The URL to the source XAP file identifies the application. You would want a new version of an application to be able to read the existing store for a previous version. Consider a game where all the high scores are stored in the application store. The user might be a little upset when all those scores disappear after they upgraded it.
Different applications can share a single site based store. However you only get those two levels of granularity, app level keyed at the XAP Url or site based, which is host and port (I'm not sure whether scheme is also part of that key).
If memory serves me right the isolated storage can be used within the scope of the application and scope of the page. So - if I understand my recollection right, I'd probably say - yes.
Edit
From a copy of Pro Silverlight 3.0 in C# that I posess :
(p. 636)
With isloated storage, a niqe storage location is created for every combination of user and application. In other words, the same computer can have multiple isloated storage locations for the same application, assymin each one is for a different user. Similarly the same user can have multiple storage locations one for each Silverlight Application
(p. 637)
... GetUserStoreForFile(). This method provides a storage site that's accessible to all silverlight applications on the same website domain, however these settings are still user specific

WPF to silverlight: what about files-IO?

We have a working WPF app that we are looking into running in the browser via Silverlight. The big question mark right now is; what kind of file access will we have (without jumping thought to many hoops)?
Can we open server-side files?
Can we open client-side files?
Can we get change notification on files (client or server side)?
Can we do the normal open/seek/write/append operations?
(Good link welcome as answeres)
This looks relevant for the client side stuff, as with the follow up/correction
Haven't found anything about loading file from the server.
Server Side Files : No, unless you serve them via a web service.
You can open files in two ways. One is isolated storage, an area that your application has, of limited size (although you can ask the user for an increase). In this you can read, write and do what you want. If you want hard disk access then you can only read, and the file must be opened from a file open dialog.
If you mean via a FileSystemWatcher - no, not even in isolated storage. Server side you can do what you want, obviously, because it's not Silverlight there. You can use duplex web services so the server could notify your silverlight application when something happens like a file change.
In isolated storage you can do what you want. Outside of that it is read operations only and the user must choose a file from the File Open dialog.
Make it XBAP and deploy it as full trust
What kinda app are you having???? first tell that and we can work the conclusions out!
UPDATE
WPF Internet Sandbox Feature List
(XBAPS & Loose XAML)
Windows Presentation Foundation
Security Sandbox
Silverlight
File access problems
You won't be able to manipulate local files with silverlight without rich client side component. That client side componetn must expose web service API and behave like local web server. With that aproach you can do almost everything that regular WPF app can do.
"Can we open server-side files?" - Yes, but requires a web service (edited)
"Can we open client-side files?" - Yes, only via an Open File window or files in isolated sotrage
"Can we get change notification on files (client or server side)?" - Yes, but only on server side.
"Can we do the normal open/seek/write/append operations?"
With System.IO.FileStream class, which is available in Silverlight, you can manipulate textual streams in memory. However, you need to fetch the stream by web services, opening it with file open window, or from isolated storage.

Resources