Xml文件写入在MVC中的存储库级别不起作用 [英] Xml file write not working in repository level in MVC

查看:61
本文介绍了Xml文件写入在MVC中的存储库级别不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目结构如下

1.ApplicationUI是一个项目

2.服务是另一个图书馆项目

3.存储库是数据库级库项目



我在存储库级别添加了xml文件,如下所示$ / b $ b存储库/ XMLUserDetails.xml



当我尝试使用下面的代码插入数据时,我收到的错误就像这样

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





无法将数据插入xml,我已在存储库级别维护xml。



我尝试过:



"

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();

推荐答案

该文件不在您要查找的位置,即你网站的根源。我们无法访问您的服务器,所以我们不能为什么,只有您可以这样做。文件根本不存在,或者它位于您正在查找的文件夹中。
The file isn't at the location you are looking for it, which is the root of your website. We can't access your server so we can't you why, only you can do that. Either the file isn't there at all or it is in a different folder to where you're looking.


这篇关于Xml文件写入在MVC中的存储库级别不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆