读取文件从网络位置 [英] Reading File From Network Location

查看:132
本文介绍了读取文件从网络位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有在其中的网络驱动器的共享文件夹的文件中的一群。我试图访问这些文件到我的code。但它给了一个错误:

  

System.IO.DirectoryNotFoundException是未处理由用户code

  FNAME = txtwbs.Text;
DirectoryInfo的objDir =新的DirectoryInfo(Y:\\);
_xmlpath = objDir +\\+ FNAME +\\+ FNAME +的.xml;
如果(File.Exists(_xmlpath))
{
    读者(_xmlpath);
}
 

我也用:

 文件=的fopen(\\\\ 10.0.2.20 \\ smartjobs \\ \\藤+ FNAME);
 

我能够从我的本地PC阅读文件,但它给例外仅适用于网络位置。请让我知道我该怎么读文件从网络共享位置。

和另外如何让文件夹的树状视图到Asp.net Web应用程序。

目录结构就是这样

  \\ 10.0.2.20 \ Smartjobs \埃托奥\
 

这是父目录据congaing文件夹号为XML文档。

解决方案

在asp.net,你不能访问网络文件夹,直接因为asp.net下匿名用户帐户运行,该帐户不能访问到该位置。

您可以给权利在共享位置每个人,看看它是否工作正常。然而,这是不可取的。

Alternativly您可能有访问网络位置的时候做模拟在asp.net code。你将不得不做implersonation与谁有权访问该共享位置的用户。

I am having Bunch of Files in A folder which is shared on Network Drive . I am trying to Access those Files into my Code . But It is giving an error:

System.IO.DirectoryNotFoundException was unhandled by user code

Fname = txtwbs.Text;
DirectoryInfo objDir = new DirectoryInfo("Y:\\");
_xmlpath = objDir + "\\" + Fname + "\\" + Fname + ".xml";
if (File.Exists(_xmlpath ))
{
    reader(_xmlpath);
}

I have Also used:

file = fopen("\\\\10.0.2.20\\smartjobs\\Eto\\"+Fname);   

I am Able to Read File from My Local PC But it is giving Exception Only for Network Location .Please let me know how can I read File From Network Shared Location .

And Also How Can I Make A tree view of Folders into Asp.net Web Application .

Directory Structure is Like that

\\10.0.2.20\Smartjobs\Eto\

this is Parent Directory It is congaing Nos of Folder having XML Documents.

解决方案

In asp.net, you cannot access network folder directly because asp.net runs under anonymous user account, that account does not have access to that location.

You can give rights to "Everyone" in that shared location and see if it is working. However this is not advisable.

Alternativly You may have to do impersonation in asp.net code when accessing network location. You will have to do implersonation with the user who has access to that shared location.

这篇关于读取文件从网络位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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