尝试在 ASP.NET 中检索路径时找不到路径的一部分

发布于 2024-11-08 12:04:56 字数 1597 浏览 3 评论 0原文

我有以下代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;

public partial class view4 : System.Web.UI.Page
{
     protected void Page_Load(object sender, EventArgs e)
     {

        string strheadlinesid = string.Empty;

        if (!IsPostBack)
        {
            if (!string.IsNullOrEmpty(Convert.ToString(
                 Request.QueryString["folder"].ToString())))
            {
                strheadlinesid = Request.QueryString["folder"].ToString();
            }
       }

       Response.Write("<table style='width: 10px; height: 10px; margin-left: 
           100px; margin-top: 10px'>");

        DirectoryInfo Dir = new DirectoryInfo(strheadlinesid);

        FileInfo[] FileList = Dir.GetFiles("*.*", SearchOption.AllDirectories);

        foreach (FileInfo FI in FileList)
        {

            Response.Write("<tr>");

            Response.Write("<td><a href= view3.aspx?file=" + FI.Name + "> " + 
                FI.Name + "</a></td>");
            Response.Write("</tr>");
        }

        Response.Write("</table>");

    }

    private object DirectoryInfo(string p)
    {
        throw new NotImplementedException();
    }


}

我通过将目录存储在文件夹中来获取目录的路径。但是,当我使用它打印该目录中的文件时,出现以下错误:

找不到路径的一部分 'C:\Users\naresh\Documents\Visual\'。

实际路径C:\Users\naresh\Documents\Visual Studio 2010\WebSites\C_Manager\Account。但是,帐户部分正在动态变化。

I have the following code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;

public partial class view4 : System.Web.UI.Page
{
     protected void Page_Load(object sender, EventArgs e)
     {

        string strheadlinesid = string.Empty;

        if (!IsPostBack)
        {
            if (!string.IsNullOrEmpty(Convert.ToString(
                 Request.QueryString["folder"].ToString())))
            {
                strheadlinesid = Request.QueryString["folder"].ToString();
            }
       }

       Response.Write("<table style='width: 10px; height: 10px; margin-left: 
           100px; margin-top: 10px'>");

        DirectoryInfo Dir = new DirectoryInfo(strheadlinesid);

        FileInfo[] FileList = Dir.GetFiles("*.*", SearchOption.AllDirectories);

        foreach (FileInfo FI in FileList)
        {

            Response.Write("<tr>");

            Response.Write("<td><a href= view3.aspx?file=" + FI.Name + "> " + 
                FI.Name + "</a></td>");
            Response.Write("</tr>");
        }

        Response.Write("</table>");

    }

    private object DirectoryInfo(string p)
    {
        throw new NotImplementedException();
    }


}

I'm getting the path of a directory by storing it in folder. However, when I use it to print the files from that directory, I'm getting the following error:

Could not find a part of the path
'C:\Users\naresh\Documents\Visual\'.

The actual path C:\Users\naresh\Documents\Visual Studio 2010\WebSites\C_Manager\Account. But, the account part is changing dynamically.

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

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

发布评论

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

评论(3

剧终人散尽 2024-11-15 12:04:56

您的问题很可能与安全权限有关。运行 Web 应用程序的典型用户帐户(网络服务或 ASP.NET 用户帐户)确实具有非常有限的权限(这是用户配置文件文件夹下的路径)。尝试修改所述文件夹的权限或以不同的身份运行您的 wep 应用程序(使用 IIS 设置或 ASP.NET 模拟)

Most probably, your issue is related to security permissions. The typical user account (network service or asp.Net user account) under which your web app runs does have very limited permissions (which is a path under user profile folder). Try modifying permissions for the said folder or running your wep app under different identity (either using IIS settings or ASP.NET impersonation)

雨落星ぅ辰 2024-11-15 12:04:56

已经有一段时间了...不知道这个问题是否已经解决...

我想知道错误消息引用的路径与您所说的尝试加载/访问的路径不同:

  • 路径:C:\ Users\naresh\Documents\Visual Studio 2010\WebSites\C_Manager\Account
  • 错误:C:\Users\naresh\Documents\Visual\

在“Visual”后面的空白处切断?

要检查的一件事(免责声明:不知道这是否是问题所在)是嵌入链接时路径名是 URL 编码的。例如,将:更改

Response.Write("<td><a href= view4.aspx?folder="
    + directory.FullName + "> "
    + directory.FullName + "</a></td>");

Response.Write("<td><a href= view4.aspx?folder="
    + Server.UrlEncode(directory.FullName) + "> "
    + directory.FullName + "</a></td>");

并查看是否有任何区别。

当然,任何尝试使用此路径访问/加载/写入/等任何内容的代码......

It's been awhile... dunno if this has already been resolved...

I'd wonder that the path cited by the error message is different from the path you say that you're trying to load/access:

  • Path: C:\Users\naresh\Documents\Visual Studio 2010\WebSites\C_Manager\Account
  • Error: C:\Users\naresh\Documents\Visual\

Cutting off at the whitespace after "Visual"?

One thing to check (disclaimer: no idea is this is the problem) is that the path name is URL-encoded when embedded in your link. E.g., change:

Response.Write("<td><a href= view4.aspx?folder="
    + directory.FullName + "> "
    + directory.FullName + "</a></td>");

to

Response.Write("<td><a href= view4.aspx?folder="
    + Server.UrlEncode(directory.FullName) + "> "
    + directory.FullName + "</a></td>");

and see if that makes any difference.

And, of course, any code that's attempting to use this path to access/load/write/etc anything...

九歌凝 2024-11-15 12:04:56

将您的用户添加到您的应用程序池身份中,它就会起作用
这都是关于权限的

Add Your user to your application pool identity and it'll work
it is all about permissions

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