SaveItemDialog access denied error on

268
1
06-07-2020 07:33 PM
by Anonymous User
Not applicable

Hi Guys,

I am using saveiteamDialog class(in pro 2.5) as shown in below code snippet

When I debugged, it seems locking the file, everytime using streamwriter it give me access denied error.

So I doubt something wrong and I tried with SaveFileDialog class from wpf build in, it is working well for me.

Just wanna check is there something wrong with file access by using saveitemdialog? 

Any tips to clean those arcgis pro thread locking object?

SaveItemDialog tmpDestination = new SaveItemDialog()
{
Title = "Output file name",
DefaultExt = "txt",
Filter = "*.txt"
};

if (tmpDestination.ShowDialog() == true)
{
try
{
string tmpPath = tmpDestination.FilePath;
using (StreamWriter sw = File.CreateText(tmpPath))
{

}
DestinationPath = tmpPath;
}
catch (Exception ex)
{
MessageBox.Show("Unexpected error occurred:"+ex.Message);



}
}
0 Kudos
1 Reply
by Anonymous User
Not applicable

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?

0 Kudos