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

问题描述 投票:0回答:3

我有以下代码:

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。但是,帐户部分正在动态变化。

c# asp.net directory filepath
3个回答
0
投票

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


0
投票

这已经有一段时间......不知道如果已经解决了......

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

  • 路径:C:\ Users \ naresh \ Documents \ Visual Studio 2010 \ WebSites \ C_Manager \ Account
  • 错误:C:\ Users \ naresh \ Documents \ 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>");

看看是否有任何区别。

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


0
投票

将您的用户添加到您的应用程序池标识,它将完成所有权限

© www.soinside.com 2019 - 2024. All rights reserved.