简体   繁体   中英

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 .

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM