1

I am using IsolatedStorage technology in my C# .net application.

My Application saves data on close in a file called MyData.dat in the isolated storage.

when i open my application it reloads that data and print it on the screen.

when i move my application to another directory, for example from D:\MyApp.exe to D:\Apps\MyApp.exe, and then run the application from it's new directory, it fails loading the file MyData.dat (FileNotFoundException) because it looking for a different MyData.dat file in a different place..

Does somebody know how i can save my isolated file - MyData.dat file in a place that no matter from where i open my App.exe it will find it?

yanivps
  • 1,993
  • 3
  • 25
  • 33
  • 1
    What does your code look like to get the store (e.g. GetStore)? – RQDQ Mar 13 '12 at 19:47
  • I tried IsolatedStorageFile.GetUserStoreForAssembly(). it didn't work, so i tried: IsolatedStorageFile.GetStore( IsolatedStorageScope.User | IsolatedStorageScope.Assembly | IsolatedStorageScope.Roaming, null, null) which didn't work also.. – yanivps Mar 13 '12 at 21:24

4 Answers4

1

Check the directory of IsolatedStorage retrived in both cases. Even if the machine is the same, expected storage path could be different for the same application in different locations.

Get isolation storage path

Community
  • 1
  • 1
Tigran
  • 61,654
  • 8
  • 86
  • 123
  • i don't see how it can help me.. i know where the file is saved. it is on %appdata%\isolatedstorage\{GUID}\MyData.dat and it creates different {GUID} directory for each run of the application by it's location – yanivps Mar 13 '12 at 20:59
  • Considering tha you're talking about `c#` and **not** `silverlight`, I would say why do not use [AplicationData](http://msdn.microsoft.com/en-us/library/system.environment.specialfolder.aspx) ? Create a directory of your app inside and hold data inside *that* folder. So the expected *location* of your application specific data could remain invariant in regard of your app location on that pc. – Tigran Mar 14 '12 at 06:43
  • Yes, actually that is what i did finally but now i am not using isolated storage but just regular FileStream.. – yanivps Mar 16 '12 at 09:36
0

I tried it myself and I noticed that the AssemblyIdentity on the IsolatedStorageFile instance changes when you move the application in another folder.

To prevent this, you have to sign the assembly and only then you can move the application into another folder and still use the same location for the isolated storeage file.

Paul
  • 1
  • 2
0

You can use IsolatedStorageFile.GetUserStoreForAssembly to get a store you can use, as long as the assmbly identity is unchanged. So it will also be independent of the location of the exe file. See the MSDN Article

Espen Burud
  • 1,871
  • 10
  • 9
  • I tried this method. it won't work when i move the exe. you can try it yourself... – yanivps Mar 13 '12 at 20:56
  • The IsolatedStorage uses cryptogaphic signature to identify your assembly, so you must sign the assembly. If the assembly is not signed and moved to another location, the assembly domain identity will change and the previous isolated storage will be unavailable. – Espen Burud Mar 14 '12 at 06:14
0

I think that your assembly info has changed in some way. For example, before moving your exe it was version 1.0.0.0 and in another directory you put different version 1.0.0.1. In this case there should be two separate directories in isolates storage location (see another answers) for these two different versions.

Or it is possible that first time you run your app in debug mode inside VS and then you moved your exe and run it directly. In this case there should be two different directories like yourappname and yourappname.vschost.

Anyway please inspect your isolated storage locations to get more info.

Dmitriy Konovalov
  • 1,777
  • 14
  • 14