将XML文件从一台服务器读取到同一网络上的另一台服务器
问题描述:
我已将我的应用程序托管在IP为12.3.4.56的服务器上,而我的数据存储位于另一台服务器上的IP为12.3.4.57的网络中。将XML文件从一台服务器读取到同一网络上的另一台服务器
我想从我的数据存储服务器读取XML文件到应用程序服务器。 当我在运行提示中触发“\\ 12.3.4.57 \ ABC \ DEF \”时,它会在两台服务器上打开正确的文件夹。我已经给每个人读取/写入文件夹的共享访问权限。
当我尝试使用下面的代码从我的应用程序服务器读取文件时,它会引发错误。
string XMLFilePath = "\\12.3.4.57\ABC\DEF\dir.xml";
XmlDocument DirDoc = new XmlDocument();
DirDoc.Load(XMLFilePath);
错误:用户名或密码不正确。
当我尝试使用下面的代码将文件从我的数据存储服务器复制到应用程序服务器时,发生了同样的错误。
string sourceFile = "\\12.3.4.57\ABD\DEF\Test123 (26).pdf";
string Folder = HttpContext.Current.Server.MapPath("~/SavedPDFs");
string destPDFFile = string.Concat(Folder, "Test123 (26).pdf");
System.IO.File.Copy(sourceFile, destPDFFile, true);
答
我相信你忘了逃避导致“许可”问题的反斜杠。
你的代码看起来应该是这样
string XMLFilePath = @"\\12.3.4.57\ABC\DEF\dir.xml"; // note the leading @ sign
XmlDocument DirDoc = new XmlDocument();
DirDoc.Load(XMLFilePath);
string sourceFile = @"\\12.3.4.57\ABD\DEF\Test123 (26).pdf"; // note the leading @ sign
string Folder = HttpContext.Current.Server.MapPath("~/SavedPDFs");
string destPDFFile = string.Concat(Folder, "Test123 (26).pdf"); // I assume that the Folder variable will have the frontslash at the end
System.IO.File.Copy(sourceFile, destPDFFile, true);
这听起来像一个文件的安全性问题,而不是一个编程的问题。 –
谢谢你在这里指导我。我应该在这里做什么来解决它?它不属于模仿问题吗? – Ronak
运行这些代码的用户必须是目标机器的用户。 – Mahdi