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.
Related
I'm a C# noob, and I've been looking for info on best practices for C# application development.
I want to have an application setting that defines where the application will write its log files & reporting output. I want this to default to %USERPROFILE%\Documents\<Vendor>\<Tool>, since these files are created for the user to actually look at and dispose of at their leisure. But, if the user wants the files to be written to some other location, I want to persist their preferences.
My research so far indicates that:
It's not generally a good idea to use environment variables directly. Instead, it's recommended to use the Environment.GetFolderPath method and the Environment.SpecialFolders enum to get access to special locations in Windows like the user profile.
But, it's recommended to use user-scope .NET Application Settings to persist settings from one session to another.
Is there any good way to reconcile best practice 1 and best practice 2? Is it actually possible to store this default location in the Application Settings in a compatible way without referencing the %USERPROFILE% environment variable?
A related question:
Assume I keep %USERPROFILE%\Documents\<vendor>\<tool> as the default value for the Setting. I want the Setting's value to be bound to a textbox on the main application form (with a Browse button to select a new path). How can I bind the Setting to a textbox in such a way that %USERPROFILE% is resolved to a conventional filesystem path (eg C:\Users\<username>\Documents\<vendor>\<tool>) for purposes of display to the user?
I think that storing paths with environment variables is actually the best way to reference a special folder as a string and still make the path easily editable by the user, should s/he decide to do so.
Environment variables can be resolved to a simple string in .NET by calling the Environment.ExpandEnvironmentVariables method. You can use this method just before presenting the path in your TextBox and thus make it easily editable for the user. Once the user customizes the path, you can store it as an absolute path from there on, I suppose.
Is there any way i can load a silverlight application from isolated storage and replace the current application ?
Short answer: no, you cannot do this. You could however store a dll, read and load it via reflection if you are in a trusted out-of-the-browser application.
Anyway I don't believe this to be a very good practice, it's very likely there is a different better way to solve your particular problem.
You can't replace the currently running application from within Silverlight code.
However you could create a single application to act as a shell. You could store assemblies or entire Xaps in isolated storage. Using the AssemblyPart class allows you to load an assembly from this storage, create an instance of an entry type and execute an entry point method.
The big caveat would be that this "stored application" would have to be coded specifically to work within your shell. You would need to provide your ways in particular to allow for "application" level state to be accessed and a means of loading content assets such as images.
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.
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
How persistent is isolated storage - does Silverlight treat it like a cache, deleting items when it needs more space, or only when the user or application request it?
There also seems to be a wide variety of means to identify isolated storage - machine, application, domain, .... What I'm having trouble with is how these all relate to the user. Is it possible, and if so how, to create and later retrieve an isolated storage file with the following properties:
The same file is used, regardless of which Windows user is logged in
The same file is used, regardless of the assembly version (updates to the xap). Instead the url would remain constant. This would have to work even offline (out of browser).
Basically I want the isolated storage to persist across application updates, and over different users logging in.
It is fairly permanent. The user could delete it if they really wanted too, but they would have to go out of their way to do so.
Here is the MSDN documentation for Isolated Storage.
IsolatedStorageFile in Silverlight a couple of statics that let you choose where you want to scope the storage:
GetUserStoreForApplication
GetUserStoreForSite
The "MachineStore" options are not available in Silverlight, there are just "Application" and "Site". Both are scoped by the user..since the files are stored under the user's AppData on Windows. Apps in-browser and out-of-browser share the same Isolated Storage stores.
[edit..I missed part of your question the first time]: The Isolated Storage stores are not part of the browser cache, so they are not cleared when the browser cache is cleared. As a developer, you can delete things programmatically. As a user, you can use the Silverlight configuration UI (i.e. the right-click menu) to manage the stores - it's called "Application Storage" to the user. Finally, an intrepid user can locate the files on disk and delete them manually...they are hidden so they won't show up in a normal search, but a determined user can still find them.