通过c#代码访问files \ folder信息 [英] Access to files\folders information via c # code

查看:75
本文介绍了通过c#代码访问files \ folder信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



当我通过Visual Studio运行以下代码时,我可以访问sherd文件夹并获取信息。

当我通过iis发布.aspx页面的最终计划并转到链接并按照相同的步骤我无法获取信息。





(我在有活动目录的组织下开发)



  private   static   long  GetDirectorySize( string  folderPath)
{
DirectoryInfo di = new DirectoryInfo(folderPath);
return di.EnumerateFiles( * ,SearchOption.AllDirectories).Sum(fi = > fi.Length);
}





有什么能帮到我吗?

解决方案

当您从Visual Studio运行时,它将获得运行Visual Studio的用户的访问权限,但是当您在IIS中托管此Web站点时,它将仅具有IIS用户访问权限,但您可以将应用程序池用户更改为另一个有权访问网络共享者等的用户..然后只有您的IIS网站才能访问共享文件夹。


您的 folderPath 字符串变量是上下文敏感的;这意味着开发机器上的给定路径在服务器上使用时不会指向相同的位置。



此变量的值是多少?


默认情况下,您的asp.net代码运行的帐户无权访问网络或其他计算机上的共享。您需要将运行代码的帐户更改为具有所需访问权限的帐户。



https://technet.microsoft.com/en-us/library/cc770966(v = ws.10)的.aspx [ ^

Hello everyone,

When I run the following code through Visual Studio, I can access the sherd folder and get information.
when I publish the final plan with .aspx page through iis and went to the link and follow the same steps I can not get information.


(I develop under the organization with the active directory)

private static long GetDirectorySize(string folderPath)
    {
        DirectoryInfo di = new DirectoryInfo(folderPath);
        return di.EnumerateFiles("*", SearchOption.AllDirectories).Sum(fi => fi.Length);
    }



Something that can help me?

解决方案

When you run from Visual studio it will get the access privileges of the user who running visual studio, but when you host this web site in IIS it will only have IIS user access as default, but you can change the app pool user to another user who having access to network sharers etc.. then only your IIS web site can access shared folders.


Your folderPath string variable is context-sensitive; it means that a given path on your development machine does not point to the same location when it is used on the server.

What is the value of this variable?


The account your asp.net code runs under by default does not have access to the network, or shares on other machines. You'll need to change the account your code is running under to an account that has the required access.

https://technet.microsoft.com/en-us/library/cc770966(v=ws.10).aspx[^]


这篇关于通过c#代码访问files \ folder信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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