string filePath = Server.MapPath("~" + model.FileUrl); System.IO.FileInfo file = new System.IO.FileInfo(filePath); if (file.Exists) { Response.Clear(); Response.AddHeader("Content-Disposition", "attachment; filename=walltafile" + file.Name.Substring(file.Name.IndexOf('.'))); Response.AddHeader("Content-Length", file.Length.ToString()); Response.ContentType = "application/octet-stream"; Response.WriteFile(file.FullName); Response.End(); } else { MessageBox.Show("该文件不存在!", this.Page); }
这个方法可以实现直接显示对话框让用户下载,在此方法里可以对权限进行判断等等,并且将文件名称隐藏。
花了点时间研究,转载请注明出处,谢谢!
ATCO
2011-02-02 0:40