使用Response.TransmitFile()下载文档时出错

时间:2012-07-02 10:24:05

标签: c# asp.net

我有一个网页,其中包含允许用户下载文档的链接。如果用户从物理位置(即C:\ filename)下载文档以及作为网站的一部分存储的文档(即〜/ Documents / filename),我正在使用的代码有效。

但是当尝试从网络位置下载文件时它不起作用并发生以下错误:“Could not find a part of the path

这是我的代码:

     Response.ContentType = "application/msword";
        Response.AppendHeader("Content-Disposition", "attachment; filename=filename.doc");
        Response.TransmitFile(Server.MapPath(@"\\ad.website.com\public\shared\filename.doc"));
        Response.End();

我已经研究过这个错误,它似乎可能是由权限或IIS设置引起的。是这种情况还是我需要更新代码?

1 个答案:

答案 0 :(得分:2)

您应该从该位置删除Server.MapPath ..
另外,它会尝试匹配当前服务器的路径。

相关问题