2017-05-09 90 views
0

我已將我的應用程序託管在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); 
+0

這聽起來像一個文件的安全性問題,而不是一個編程的問題。 –

+0

謝謝你在這裏指導我。我應該在這裏做什麼來解決它?它不屬於模仿問題嗎? – Ronak

+0

運行這些代碼的用戶必須是目標機器的用戶。 – Mahdi

回答

0

我相信你忘了逃避導致「許可」問題的反斜槓。

你的代碼看起來應該是這樣

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); 
相關問題