0
这是我在索引视图上的动作链接。mvc控制器下载文件路径出错
@Html.ActionLink("Download File", "Download", new { fileName = Model.OriginalRecordRelativeFilePath })
public FileResult Download(string fileName)
{
try
{
var fs = System.IO.File.OpenRead(Server.MapPath(ConfigurationHelper.IntegrationInterfaceFolderPath + fileName));
// ConfigurationHelper.IntegrationFolderPath is a path for C:\Data\IntergrationInterface\
return File(fs, "application/octet-stream", fileName);
}
catch
{
throw new HttpException(404, "Couldn't find " + fileName);
}
}
我试着从C下载文件:\ DATA \ IntergrationInterface \文件名。但它无法找到C:\ Data \ IntergrationInterface \ fileName的路径并抛出异常(Couldnt find fileName)。我可以知道有什么方法可以在同一台计算机上运行本地主机web服务时从本地c下载文件?谢谢。
这个例外不是谎言。文件是否存在?验证路径,最好通过将其存储在单独的变量中。用户本站运行是否具有读取文件的权限? – CodeCaster 2014-10-31 08:49:36
是的。该文件存在。我在C:\ Data \ IntergrationInterface \ path中创建了一个名为path的虚拟文件。用户本网站编码为系统管理员。所以它有权限读取文件。 – AhYap 2014-10-31 08:57:16
将代码更改为'string path = ConfigurationHelper.IntegrationInterfaceFolderPath + fileName; path = Server.MapPath(path); var fs = System.IO.File.OpenRead(path);'。检查每个步骤的变量。 – CodeCaster 2014-10-31 08:58:50