My project structure is like below
1. ApplicationUI is one project
2. Service is another library project
3. Repository is db level library project
and i have added the xml file in Repository level like below
Repository/XMLUserDetails.xml
when i tried to insert the data by using the below code then i am getting the error like this "
Could not find a part of the path
"
Not able to insert the data into xml whne i have maintained xml in Repository level.
What I have tried:
string xmlFileName = "~\\XMLUserDatabase.xml";
XmlDocument oXmlDocument = new XmlDocument();
oXmlDocument.Load(HttpContext.Current.Server.MapPath(xmlFileName));
XmlNodeList nodelist = oXmlDocument.GetElementsByTagName("UsrDetails");
XDocument xmlDoc = XDocument.Load(HttpContext.Current.Server.MapPath(xmlFileName));
xmlDoc.Element("UsrDetails")
.Add( new XElement("EmailAddress", objUserDetailsRequest.EmailAddress),
new XElement("Password", objUserDetailsRequest.Password));
xmlDoc.Save(HttpContext.Current.Server.MapPath(xmlFileName));
System.Xml.XmlDocument myXml = new System.Xml.XmlDocument();
myXml.Load(System.Web.Hosting.HostingEnvironment.MapPath("~/XMLUserDetails.xml"));
System.Xml.XmlNode xmlNode = myXml.DocumentElement.FirstChild;
System.Xml.XmlElement xmlElement = myXml.CreateElement("UserDetails");
xmlElement.SetAttribute("EmailAddress", objUserDetailsRequest.EmailAddress);
xmlElement.SetAttribute("Password", objUserDetailsRequest.Password);
myXml.DocumentElement.InsertBefore(xmlElement, xmlNode);
myXml.Save(System.Web.Hosting.HostingEnvironment.MapPath("~/XMLUserDetails.xml"));
XmlTextReader xmlReader = new XmlTextReader(System.Web.Hosting.HostingEnvironment.MapPath("~/XMLUserDetails.xml"));
xmlReader.Close();