string path = Server.MapPath(file.Path);
System.IO.FileInfo files = new System.IO.FileInfo(path); if (files.Exists)
{
Response.Clear();
string s = HttpUtility.UrlEncode(System.Text.UTF8Encoding.UTF8.GetBytes(files.Name));
Response.AddHeader("Content-Disposition", "attachment; filename=" + s);
Response.AddHeader("Content-Length", files.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.WriteFile(files.FullName);
Response.End(); }
else
{
Response.Write("你所选中文件不存在!");
}
出现错误说 不是有效的虚拟路径,不知道咋办了,请大家帮忙。是实现下载功能的。
System.IO.FileInfo files = new System.IO.FileInfo(path); if (files.Exists)
{
Response.Clear();
string s = HttpUtility.UrlEncode(System.Text.UTF8Encoding.UTF8.GetBytes(files.Name));
Response.AddHeader("Content-Disposition", "attachment; filename=" + s);
Response.AddHeader("Content-Length", files.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.WriteFile(files.FullName);
Response.End(); }
else
{
Response.Write("你所选中文件不存在!");
}
出现错误说 不是有效的虚拟路径,不知道咋办了,请大家帮忙。是实现下载功能的。
System.IO.FileInfo files = new System.IO.FileInfo(path);
string path = HttpContext.Current.Server.MapPath(paths);
不行了
如果是固定的文件,就复制到服务器虚拟目录下面就行了,如在虚拟目录下面建立UpLoad文件夹,把文件放进去,数据库保存这个文件名,就可以像上面那样用了:string path = HttpContext.Current.Server.MapPath("~/UpLoad/") + s_fileName; //s_fileName为文件名
System.IO.FileInfo files = new System.IO.FileInfo(path);
//。其它代码