如何使用C#code访问共享网络驱动器文件 [英] How to Access Shared Network drive File using C# code
问题描述
手动我已映射网络驱动器的 Y:// 我的系统.Drive是有曼尼文件夹文件具有相同文件夹中每个Containg单独的XML文件
Manually I Have Mapped Network Drive Y:// To My System .Drive is having Manny Folders each Containg Single XMl File having Same as Folder .
在这里,我想读XML文件从网络位置。但它给异常目录未找到。低于code,我用了点。
Here I am Trying to Read Xml File From Network Location . But It is Giving Exception Directory Not Found . Below Code I am Using For that .
Fname = txtwbs.Text;
DirectoryInfo objDir = new DirectoryInfo("Y:\\");
\\Y:\\
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
_xmlpath = objDir + "\\" + Fname + "\\" + Fname + ".xml";
if (File.Exists(_xmlpath ))
{
reader(_xmlpath);
}
}
下面是FNAME文件夹名称也XML名称.Whatever用户输入文件的名称。
Here Fname is Folder Name Also Xml Name .Whatever User Will Enter the Name of File .
推荐答案
这抢code:的http://引擎收录.COM / RZnydz4Z
然后在您的global.asax的的Application_Start把这个:
Then on the Application_Start of your global.asax put this:
protected void Application_Start(object sender, EventArgs e)
{
Utilities.Network.NetworkDrive nd = new Utilities.Network.NetworkDrive();
nd.MapNetworkDrive(@"\\server\path", "Z:", "myuser", "mypwd");
}
然后,只需使用像一个正常的网络驱动器,如:
Then just use like a normal network drive, like this:
File.ReadAllText(@"Z:\myfile.txt");
这篇关于如何使用C#code访问共享网络驱动器文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!