javascript 路径错误中的非法字符
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19190645/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
illegal characters in path error
提问by user793468
I am trying to launch an excel file but get an error, Am I missing something?
我正在尝试启动一个 excel 文件但出现错误,我是否遗漏了什么?
I try to launch an excel file but get:
我尝试启动一个 excel 文件,但得到:
illegal characters in path
路径中的非法字符
Controller Action:
控制器动作:
public ActionResult ExportData(DateTime Date)
{
return File("~\Reports\ExcelExport.xlsm?Date=" + Date, "application/vnd.ms-excel" , Server.UrlEncode("~\Reports\ExcelExport.xlsm?Date=" + Date));
}
JavaScript:
JavaScript:
function ExportToExcel() {
var link = '/Report/ExportData';
var Date= $("#Date").val();
$.ajax({
url: link,
contentType: 'application/json; charset=utf-8',
data: { Date: Date},
success: function (result) {
},
error: function (result) {
}
});
};
回答by wagesj45
You're including the string value of the DateTime parameter in your path. That will look something like this: 10/4/2013 5:00:17 PM. Both /and :are invalid characters in a Windows path.
您在路径中包含 DateTime 参数的字符串值。这看起来像这样:10/4/2013 5:00:17 PM。无论/和:是在Windows路径无效字符。
回答by John
Question marks are not valid characters for filenames.
问号不是文件名的有效字符。
http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx
回答by Moho
You're passing in a hybrid URL/physical file path. Try something like this to get the physical file path if it's on disk:
您传入的是混合 URL/物理文件路径。如果它在磁盘上,请尝试这样的操作来获取物理文件路径:
string filePath = Server.MapPath(Url.Content("~/Reports/ExcelExport.xlsm"));