System.IO.DirectoryInfo 的奇怪行为。存在功能

发布于 2024-10-02 10:20:57 字数 578 浏览 0 评论 0原文

我正在使用 c# 和 asp 开发一个应用程序。它需要访问本地网络中的某些地方。表单中有一个文本框,它接受用户要访问的路径并将其存储到名为 location 的字符串变量中。

如果应用程序在 Windows 7 中运行,则 if 循环始终返回 false,并且仅当我从已安装的应用程序运行时才会发生这种情况,否则如果路径为 true,它将返回 true。代码如下:

文本框 BackupLocation 的输入如下所示

 \\192.168.0.33\Others (F)

。如果应用程序托管在 Windows XP 系统上,则可以正常工作

 System.IO.DirectoryInfo locationInfo = new System.IO.DirectoryInfo(BackupLocationTxt.Text);
        if (locationInfo.Exists) // always return false  if the application run in windows 7
       {

       }

为什么会发生这种情况?

I am developing an application using c# and asp. It need to access some places in the local network . There is a text box in the form which accept the path to be accessed from the user and will store it to a string variable named location.

The if loop always return false if the application run in windows 7. and it occurs only when I run from the installed application, otherwise it will return true if the path is true. Here is the code:

The input to textbox BackupLocation is like this

 \\192.168.0.33\Others (F)

. It work fine if the application is hosted on a system which have windows XP

 System.IO.DirectoryInfo locationInfo = new System.IO.DirectoryInfo(BackupLocationTxt.Text);
        if (locationInfo.Exists) // always return false  if the application run in windows 7
       {

       }

Why this happens ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

司马昭之心 2024-10-09 10:20:57

发生这种情况是因为您运行应用程序的用户无权读取这些文件夹。您可能需要向运行站点的帐户授予对这些文件夹的读取权限。

This happens because the user you are running your application under doesn't have authorization to read those folders. You might need to grant read access to those folders to the account you are running your site under.

陈年往事 2024-10-09 10:20:57

尝试使用 System.IO.Directory.Exists(string path) 代替。

Try System.IO.Directory.Exists(string path) instead.

原来分手还会想你 2024-10-09 10:20:57

您的 ASP.NET 应用程序没有访问本地网络中其他计算机上的文件夹的权限。

尝试使用在 LocalService 帐户下启动的 Windows 服务。

Your ASP.NET application doesn't have permissions to the folder on other computer in local network.

Try use windows service started under LocalService account.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文