Madurika Welivita
Madurika Welivita

Reputation: 900

microsoft.win32.savefiledialog issue in windows xp

I am using microsoft.win32.savefiledialog to save a file inside a folder. Only in windows XP, after saving file in a folder (ex: abc) , I cannot delete abc folder. Error message displays saying that another process is using this. Seems like handles are remaining on selected folder. Please give me a solution on this.

Following is my save file dialog code:

SaveFileDialog fileDialog = new SaveFileDialog();

fileDialog.DefaultExt = !string.IsNullOrEmpty(this.DefaultExtension) ? this.DefaultExtension : "*.*";
fileDialog.Filter = !string.IsNullOrEmpty(Filter) ? Filter : "All Files|*.*";
fileDialog.FileName = !string.IsNullOrEmpty(this.FileName) ? this.FileName : string.Empty;
fileDialog.InitialDirectory = !string.IsNullOrEmpty(this.DefaultPath) ? this.DefaultPath : string.Empty;

if (fileDialog.ShowDialog().Value == true)
{
    fileName = fileDialog.FileName;
}
else
{
    fileName = string.Empty;
}            

return fileName;

EDITED :

This is common for System.Windows.Forms also, I tried lot, issue happnes when I select a folder from file dialog window. no need to do anything after that, just select a folder form save file dialog. that foldercannot be deleted .

Upvotes: 0

Views: 488

Answers (1)

Hans Passant
Hans Passant

Reputation: 941317

This is entirely normal. It is not another process that has the directory object opened, it is your process. Your code made the directory the default working directory of your process. Something you can see from the Environment.CurrentDirectory property.

Set the SaveFileDialog.RestoreDirectory property to true to avoid this.

Upvotes: 3

Related Questions