AHungry_Mind
May 19th, 2005, 06:13 AM
I am getting trouble with saveFileDialog :( I could not find the mistake:(.Actually program works ;but when i savefileDialog appears and i write the name of the file when i press the save button it throws an exception and says that:
The process can not access the file "bla bla\My Documents\asd.txt" because it is being used by another process and your access denied .
After this error when i try to debug with the code breakpoints even Vs .Net gone mad and gives some errors like you can not access the phonebook.exe or cs.
My saveFileDialog looks like this:
private void saveAsItm_Click(object sender, System.EventArgs e)
{
check:
System.IO.Stream myStream ;
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
//ArrayList arr =new ArrayList();
saveFileDialog1.Filter = "Txt files (*.txt)|*.txt|All files (*.*)|*.*" ;
saveFileDialog1.FilterIndex = 2 ;
saveFileDialog1.RestoreDirectory = true ;
saveFileDialog1.Title="Save as";
if(saveFileDialog1.ShowDialog() == DialogResult.OK)
{
if((myStream = saveFileDialog1.OpenFile()) != null)
{
try
{
if(saveFileDialog1.FileName.EndsWith("txt"))
{
System.IO.StreamWriter sw=new System.IO.StreamWriter(saveFileDialog1.FileName);
for(int i=0;i<PersonList.Capacity;i++)//PersonList is a global ArrayList
{
sw.Write((PersonList[i]).ToString());//Writes the contents of
sw.Close();
//myStream.Close();
}
}
else {
MessageBox.Show("Error: Check if you entered the file extension properly or not","Warning",MessageBoxButtons.OK,MessageBoxIcon.Warning);
goto check;
}
MessageBox.Show("Your list saved.");
}
catch(Exception e1)
{
MessageBox.Show("Error: "+e1.ToString(),"Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
finally
{
myStream.Close();
}
}
The process can not access the file "bla bla\My Documents\asd.txt" because it is being used by another process and your access denied .
After this error when i try to debug with the code breakpoints even Vs .Net gone mad and gives some errors like you can not access the phonebook.exe or cs.
My saveFileDialog looks like this:
private void saveAsItm_Click(object sender, System.EventArgs e)
{
check:
System.IO.Stream myStream ;
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
//ArrayList arr =new ArrayList();
saveFileDialog1.Filter = "Txt files (*.txt)|*.txt|All files (*.*)|*.*" ;
saveFileDialog1.FilterIndex = 2 ;
saveFileDialog1.RestoreDirectory = true ;
saveFileDialog1.Title="Save as";
if(saveFileDialog1.ShowDialog() == DialogResult.OK)
{
if((myStream = saveFileDialog1.OpenFile()) != null)
{
try
{
if(saveFileDialog1.FileName.EndsWith("txt"))
{
System.IO.StreamWriter sw=new System.IO.StreamWriter(saveFileDialog1.FileName);
for(int i=0;i<PersonList.Capacity;i++)//PersonList is a global ArrayList
{
sw.Write((PersonList[i]).ToString());//Writes the contents of
sw.Close();
//myStream.Close();
}
}
else {
MessageBox.Show("Error: Check if you entered the file extension properly or not","Warning",MessageBoxButtons.OK,MessageBoxIcon.Warning);
goto check;
}
MessageBox.Show("Your list saved.");
}
catch(Exception e1)
{
MessageBox.Show("Error: "+e1.ToString(),"Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
finally
{
myStream.Close();
}
}