Click here to Skip to main content
15,888,461 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello All,
System.IO Exception The process cannot access the file because it is used by another process exception is thrown
but in my code i have used using block as well as close also but also exception is thrown what shall i do for this?
One process is reading the contents of file while writing the file at that time exception is occured how to avoid this?
C#
private static void WritToXmlFile(string xmlfile, XmlDocument doc)
       {
         using (StreamWriter sw = new StreamWriter(xmlfile, false))
               {
                   sw.Write(doc.OuterXml);
                   sw.Close();
               }
      }
Posted
Updated 2-Apr-12 23:59pm
v3

may b the location where ur file is saved is readonly,
 
Share this answer
 
Comments
yeshgowda 3-Apr-12 4:43am    
No It is not readonly but this exception is occured randomly not always
Close visual studio. And restart then Try to run your application without debugging.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900