ASP.net 相对路径不起作用?

发布于 2024-09-10 19:39:25 字数 581 浏览 4 评论 0原文

这应该很简单,但它不起作用。

我的项目根目录下有一个文件。我想这样称呼它。

GetWorkbook("tplBud806_wRevenue.xls")

我将项目发布到服务器并尝试运行它,但服务器说找不到它。

Could not find file 'c:\windows\system32\inetsrv\tplBud806_wRevenue.xls'.

这不是它应该走的路。它应该位于 E:\IIServer\rootwww\reports\tplBud806_wRevenue.xls 下。

我认为相对路径应该从项目运行的路径开始。我也尝试过。

GetWorkbook("/tplBud806_wRevenue.xls")
GetWorkbook("\tplBud806_wRevenue.xls")
GetWorkbook("~/tplBud806_wRevenue.xls")
GetWorkbook("~\tplBud806_wRevenue.xls")

我缺少一些设置吗?这一定是一些简单的事情...

This should be pretty simple but it's not working.

I have a file underneath the root of my project. I want to call it like this.

GetWorkbook("tplBud806_wRevenue.xls")

I publish the project out to the server and try to run it and the server says it can't find it.

Could not find file 'c:\windows\system32\inetsrv\tplBud806_wRevenue.xls'.

That's not the path it should be taking. It should be under E:\IIServer\rootwww\reports\tplBud806_wRevenue.xls.

I thought relative paths were supposed to start from the path that the project was running in. I've also tried.

GetWorkbook("/tplBud806_wRevenue.xls")
GetWorkbook("\tplBud806_wRevenue.xls")
GetWorkbook("~/tplBud806_wRevenue.xls")
GetWorkbook("~\tplBud806_wRevenue.xls")

Is there some setting I'm missing? It's got to be something simple...

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

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

发布评论

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

评论(5

诗笺 2024-09-17 19:39:29

您的应用程序正在由位于错误目录中的 w3wp.exe 加载的 AppDomain 中运行。这意味着尝试查找任何文件都将从该目录开始。您应该使用 Page.MapPath ,正如其他人提到的。它告诉应用程序开始查找您的 aspx 所在的文件夹。

Your application is running in an AppDomain loaded by the w3wp.exe located in the directory in your error. Which means that trying to look for any file will start in that directory. You should use Page.MapPath, as mentioned by others. It tells the application to start looking in the folder your aspx is in.

白色秋天 2024-09-17 19:39:29

GetWorkBook(Server.MapPath("~/tplBud806_wRevenue.xls")); 如果 .XLS 文件位于项目的根目录。

您还可以将 ~ 与 ResolveURL() 结合使用来访问站点中的 URL。因此 ~ 将替换为项目的根 URL

示例:

ResolveURL("~\tplBud806_wRevenue.xls")

将转换为
http://myproject.url/website/tplBud806_wRevenue.xls

如果您需要磁盘访问(如示例所示),请使用 Server.MapPath

看看这个 SO 帖子 了解有关 Server.MapPath 的更多信息

GetWorkBook(Server.MapPath("~/tplBud806_wRevenue.xls")); If the .XLS file is at the root of your project.

You can use also use ~ in conjuction with ResolveURL() to access an URL in your site. So ~ will be replaced by the root URL of your project

Example:

ResolveURL("~\tplBud806_wRevenue.xls")

will be transformed to
http://myproject.url/website/tplBud806_wRevenue.xls

If you need disk access, like in your example, use Server.MapPath

Look at this SO post to learn more about Server.MapPath

如日中天 2024-09-17 19:39:28

服务器.MapPath?

Server.MapPath?

笔芯 2024-09-17 19:39:27
GetWorkBook(Server.MapPath("tplBud806_wRevenue.xls"));
GetWorkBook(Server.MapPath("tplBud806_wRevenue.xls"));
冬天旳寂寞 2024-09-17 19:39:27

GetWorkbook 不是 ASP.NET 函数,它可能默认为调用它的进程从中启动的文件夹。本例中的进程是 IIS 进程,可能在该文件夹中启动。

GetWorkbook is not an ASP.NET function, and it likely defaults to the folder that the process calling it was started from. The process in this case is an IIS process and probably started in that folder.

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