Deleting Files from IsolatedStorage

G

Guest

Hi,

I've been having some frustrations with deleting files from the Isolated
Storage directories. Basically, I want my application to remove all
instances of configuration information for my application when the
application is uninstalled. So, I created an uninstaller class that
overrides the uninstall method, as follows:

private void DeleteSettings(){
// Try and delete the settings.config
// created during the saving of user preferences
try {
IsolatedStorageFile isoFile =
IsolatedStorageFile.GetStore(IsolatedStorageScope.User |
IsolatedStorageScope.Assembly, null, null);

String[] dirNames = isoFile.GetDirectoryNames("*");
String[] fileNames = isoFile.GetFileNames("*");

// List the files currently in this Isolated Storage.
// The list represents all users who have personal
// preferences stored for this application.
if (fileNames.Length > 0) {
for (int i = 0; i < fileNames.Length; ++i) {
// Delete the files.
isoFile.DeleteFile(fileNames);
}
// Confirm that no files remain.
fileNames = isoFile.GetFileNames("*");
}
}catch (Exception e) {
MessageBox.Show(e.Message);
}

This was code taken from the MSDN website. When I run this code right after
creating the file in Isolated Storage, it works fine, and the file is
deleted. But when I run this code from the uninstaller class, no files are
returned in the GetFiles("*") method. Is there something else I should be
doing when I'm in the uninstall process?

Thanks
Josh
}
 
G

Greg Young [MVP]

Its how you are defining your isolated storage ...

IsolatedStorageFile.GetStore(IsolatedStorageScope.User |
IsolatedStorageScope.Assembly, null, null);

http://msdn2.microsoft.com/en-us/library/system.io.isolatedstorage.isolatedstoragescope(VS.80).aspx

Note that it is being scoped to the assembly .. as such when the uninstall
program runs (from a different assembly) it will not be accessing the same
isolated storage as the application.

This is assuming you are dealing with two seperate assemblies, the other
possibility depending on the setup that you are doing is that the code could
be running in two different user contexts which would also cause the
isolated storage to vary.

Cheers,

Greg
 
A

Aaron G

Hey, just a thought... Why not add a command line parameter to the
application you are uninstalling that will delete the isolated storage
for you?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top