Tutorial :.NET: How to write a file with limited permissions for temporary data



Question:

I have a library I am using where the only way to pass in config data is by giving it a filename where it can go to read the data. I am writing another shared library to be used by all of our applications which consumes this, and so I need a way to store some data in a local temp folder, and then delete once I have called the shared library. Is there a simple way of doing this, without knowing the permissions that the application will have? I ma thinking IsolatedStorage because I have seen that used by ClickOnce applications, but I don't know if it allows to get the file path so I can pass it to the library.


Solution:1

You can also look at string tempPath = System.IO.Path.GetTempPath(); as the user should always have full access to that directory.


Solution:2

You can use Path.GetTempFileName(). This will allow you to get a temporary filename to a temp directory that your user has access to. The advantage of this over GetTempPath is that it will also generate a random file name for you.


Solution:3

IsolatedStorage is basically a closed of area on the endusers filesystem. Compare it to cookies. Browsers can only store information on an end user's machine as a cookie, the browsers determines the location of the cookie storage. You can manipulate files in the isolatedstorage, but cannot go outside it.

My question, what kind of app is it (Windows, Web, Silverlight)? If it's a windows app you can basically do anything you want, since it's installed on the end user's machine.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »