Save XML
-
Hi, After modifying the content in xml file, I tried to save in the same location. It is throwing an exception that the file is already in use. So unable to save in the same location. When I tried to save in the other location, its working fine. Please guide me to save in the same path. thanks in advance.
string filePath="C:\\test\\sample.xml";
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(filePath);//made some changes in xmlDoc
xmlDoc.Save(filePath); //exception
-
Hi, After modifying the content in xml file, I tried to save in the same location. It is throwing an exception that the file is already in use. So unable to save in the same location. When I tried to save in the other location, its working fine. Please guide me to save in the same path. thanks in advance.
string filePath="C:\\test\\sample.xml";
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(filePath);//made some changes in xmlDoc
xmlDoc.Save(filePath); //exception
try renaming the modified xml document.like original filename + date modified.
-
try renaming the modified xml document.like original filename + date modified.
-
Hi, After modifying the content in xml file, I tried to save in the same location. It is throwing an exception that the file is already in use. So unable to save in the same location. When I tried to save in the other location, its working fine. Please guide me to save in the same path. thanks in advance.
string filePath="C:\\test\\sample.xml";
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(filePath);//made some changes in xmlDoc
xmlDoc.Save(filePath); //exception
Hi Narvish, There is no problem with code, the same is worked for me. i would suggest to make the document object null in finally block. In your case the worker process might be using the file in memory. Regards Surender No Defeat Is Final Until You Stop Trying!.......
-
Hi Narvish, There is no problem with code, the same is worked for me. i would suggest to make the document object null in finally block. In your case the worker process might be using the file in memory. Regards Surender No Defeat Is Final Until You Stop Trying!.......
-
As per your suggestion, I kept the code in try block and I added
finally
{
xmlDoc = null;
}Still it is throwing exception that process cannot use that file.. because it is using by other thread. :(
Make sure the file and folder have proper permissions set and file is not kept open anywhere. remove file manually and try again. Regards Surender No Defeat Is Final Until You Stop Trying!.......
-
Make sure the file and folder have proper permissions set and file is not kept open anywhere. remove file manually and try again. Regards Surender No Defeat Is Final Until You Stop Trying!.......