是一个内容管理系统,由于权限设置的原因,坚决不允许将文档或者程序存放在一个IIS无法访问的目录,以免造成泄密事件。因此要采用利用Asp.Net读出文件内容后回写到浏览器中的方法,看了uestc95 的[.NET Tips 1001]ASP.NET直接下载一个文件,而不是在IE中打开它 后很有启发,不过偷懒的天性是我觉得这个方法有点麻烦。好在发现Response.Writefile 这个方法,可以最大限度的减少同志们的工作量。,代码如下
Response.Clear()
Response.ContentType = "application/octet-stream"
Response.AddHeader("Content-Disposition", "attachment;FileName=" + HttpUtility.UrlEncode(filename, System.Text.Encoding.UTF8))
Response.WriteFile(filepath+filname)
Response.End()
当然大家可以在这里添加一些权限判断的代码。
http://support.microsoft.com/default.aspx?scid=kb;EN-US;317719
How To Export Data in a DataGrid on an ASP . NET WebForm to Microsoft Excel