I managed to solve this issue today by force and cleaning this object via GC.
System.GC.Collect();
System.GC.WaitForPendingFinalizers();
But it only solve for new file creation, overwriting the existing file still giving me the same error.
Below is modified code.
SaveItemDialog tmpDestination = new SaveItemDialog()
{
Title = "Output file name",
DefaultExt = "txt",
Filter = "*.txt"
};
if (tmpDestination.ShowDialog() == true)
{
try
{
string tmpPath = tmpDestination.FilePath;
tmpDestination = null;
System.GC.Collect();
System.GC.WaitForPendingFinalizers();
using (StreamWriter sw = File.CreateText(tmpPath))
{
}
DestinationPath = tmpPath;
}
catch (Exception ex)
{
MessageBox.Show("Unexpected error occurred:"+ex.Message);
}
}
Hi Uma Harano, Any comment on this way of solution, do we have any alternate idea? I read about that GC collection before, it might affect a bit of performance. So far looking good for me.
And not sure about overwriting file issue as well, when i open the same file with notepad, I can modify it. Any idea?