尝试在 ASP.NET 中检索路径时找不到路径的一部分
我有以下代码:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您的问题很可能与安全权限有关。运行 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)
已经有一段时间了...不知道这个问题是否已经解决...
我想知道错误消息引用的路径与您所说的尝试加载/访问的路径不同:
在“Visual”后面的空白处切断?
要检查的一件事(免责声明:不知道这是否是问题所在)是嵌入链接时路径名是 URL 编码的。例如,将:更改
为
并查看是否有任何区别。
当然,任何尝试使用此路径访问/加载/写入/等任何内容的代码......
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:
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:
to
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...
将您的用户添加到您的应用程序池身份中,它就会起作用
这都是关于权限的
Add Your user to your application pool identity and it'll work
it is all about permissions