b/s程序,报由于出现错误 c00ce514 而导致此项操作无法完成
protected void B_DownLoad_Click(object sender, EventArgs e){
string file = String.Empty;
for (int i = 0; i < this.DL_Image_Properties.Items.Count; i++)
{
if (((CheckBox)this.DL_Image_Properties.Items[i].FindControl("CB_Image_Properties")).Checked == true)
{
file = ((ImageButton)this.DL_Image_Properties.Items[i].FindControl("Image1")).ImageUrl.ToString();
string From = file.Replace(Class.Setting.usImageHttp(), usImageAddress);
FileInfo fi = new FileInfo(From);
//以字符流的形式下载文件
FileStream fs = new FileStream(fi.DirectoryName + fi.Name.Insert(0, "\\"), FileMode.Open);
byte[] bytes = new byte[(int)fs.Length];
fs.Read(bytes, 0, bytes.Length);
fs.Close();
Response.ContentType = "application/octet-stream";
//通知浏览器下载文件而不是打开
Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(fi.Name, System.Text.Encoding.UTF8));
Response.BinaryWrite(bytes);
Response.Flush();
Response.End();
}
}
} 这是写的代码 --------------------编程问答-------------------- fs.Close();
不应先关闭,参考
using (FileStream fso = new FileStream(Server.MapPath(DownAdress), FileMode.Open,FileAccess.ReadWrite,FileShare.Inheritable))
{
string[] filename=DownAdress.Split(new char[]{'/'});
int len = Convert.ToInt32(fso.Length);
byte[] FileObj = new byte[len];
fso.Read(FileObj, 0, len);
Response.AddHeader("Content-Disposition", string.Format("attachment; filename={0}", HttpUtility.UrlEncode(filename[filename.Length - 1]), System.Text.Encoding.UTF8));
Response.AddHeader("Content-Length", len.ToString());
Response.ContentType = "application/octet-stream";
Response.Charset = "UTF-8";
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.BinaryWrite(FileObj);
Response.Flush();
Response.Clear();
fso.Close();
} --------------------编程问答-------------------- 有谁清楚呢? --------------------编程问答-------------------- 这个是UpdatePanel的问题,你是不是在UpdatePanel调用这个事件的???
补充:.NET技术 , ASP.NET