Sourabh Choubey

Sourabh Choubey

  • NA
  • 236
  • 41.6k

How to release the object of xdocument

Aug 3 2016 4:40 AM
I am getting this error 
 

The process cannot access the file 'G:\27thJune2016\OutClique.UI\XmlFiles\Blog.xml' because it is being used by another process.

here is my code..
XmlDocument XDOC = new XmlDocument();
XDOC.Load(System.Web.HttpContext.Current.Server.MapPath("~/XmlFiles/Blog.xml"));
XmlNode RootNode = XDOC.SelectSingleNode("//Blogs");
XmlNode childnode = XDOC.SelectSingleNode("/Blogs/IDs");
//check whether childnode exist or not.
if (childnode != null)
childnode.ParentNode.RemoveChild(childnode);
XmlElement XEle = XDOC.CreateElement("IDs");
XEle.SetAttribute("id", Convert.ToString(ID));
RootNode.AppendChild(XEle);
XDOC.Save(System.Web.HttpContext.Current.Server.MapPath("~/XmlFiles/Blog.xml"));(in this line i am facing the ;problem)
 

Answers (1)