ASP.net 相对路径不起作用?
这应该很简单,但它不起作用。
我的项目根目录下有一个文件。我想这样称呼它。
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您的应用程序正在由位于错误目录中的 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.
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 projectExample:
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
服务器.MapPath?
Server.MapPath?
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.