下载代码

来源:互联网 发布:linux cp 复制文件夹 编辑:程序博客网 时间:2024/04/30 08:14
  //以下是下载操作
string id = this.gvwDownLond.DataKeys[e.NewEditIndex].Value.ToString();
            AccessoryFile file = AccessoryFileManage.GetAccessoryFileModel(int.Parse(id));//根据编号得到对象
            //以下是下载操作
            System.IO.FileInfo fileInfo = new System.IO.FileInfo(file.AccessoryPath);
            Response.Clear();
            Response.ContentType = "application/octet-stream";//设置下载头部样式
            Response.AddHeader("Content-Disposition", "acctachment;filename=" + HttpUtility.UrlEncode(fileInfo.Name, System.Text.Encoding.UTF8));
            Response.AddHeader("content-length", fileInfo.Name.Length.ToString());//设置下载头部标题
            Response.Flush();//清除文件流
            Response.WriteFile(file.AccessoryPath);
原创粉丝点击