2012-10-08 30 views
0

我有一個二進制讀取讀取文件路徑從WWW文件夾內閱讀文件

BinaryWriter bw2 = new BinaryWriter(File.Open(@"c:\test\test6.xml", FileMode.OpenOrCreate)); 

我所設定的路徑是C:\測試\的test.xml 但是它需要讀取的文件從WWW文件夾的託管網站 所以WWW \測試\的test.xml 應該〜\測試\的test.xml? 不知道。 感謝您的幫助

回答

2

退房使用Server.Mappath()在你的情況http://msdn.microsoft.com/en-us/library/ms524632(v=VS.90).aspx

所以,你在這之後是:

using (BinaryWriter bw2 = new BinaryWriter(File.Open(Server.MapPath(@"~\test\test6.xml", FileMode.OpenOrCreate))) 
{ 
    ... 
} 

請注意,我添加了使用(),這是一個最佳實踐與昂貴的資源,如文件的工作。

當然,你真的應該獨立出來,從對象創建文件打開,所以你可以在你的代碼有更好的診斷。