views:

55

answers:

2

In my C# application, if I wanted to be able to download an "add-in" from our website and store it locally on the user's computer, and then run it (assume it's an assembly DLL or EXE, doesn't matter), I assume I can't store it in a subdirectory of my Program Files folder, and that's not really the right place for it since add-ins are user-specific. Where should I store these, and what kinds of trust/security issues might I run into?

+3  A: 

The application data directory of the current user would be one place to store them.

string basePath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
basePath = System.IO.Path.Combine(basePath, "MyProgram");
if (!Directory.Exists(basePath))
  Directory.CreateDirectory(basePath);

Trying to write anything inside of Program files after installation will run into problems in Vista, Windows 2008 server, Windows 7 and later. Unless of course your application requires elevation. Also you mentioned your files are specific per user.

Brian R. Bondy
+1  A: 

Use the IsolatedStorage class provided in .NET for storing user specific stuff.

More information: Working with Isolated Storage in .NET

Ian
Anyone want to provide a reason why this method is better or worse than Brian's?
Scott Whitlock
Scott, it isn't a lot different. I think the storage location is slightly different to the one that would be used in Brian's answer. Generally its the recommended according to the .NET books I've read for user/app specific data. Depending on the system deployed you've got a much better change of allowing privileges to use IsolatedStorage using CAS if you run into problems that you might not have using Brian's approach.
Ian
According to this: http://stackoverflow.com/questions/882490/how-to-decide-where-to-store-per-user-state-registry-appdata-isolated-storage/882496#882496 isolatedstorage is inside the ApplicationData folder anyway, so I think this is the better answer.
Scott Whitlock