这是我下载的Code
string invoiceNo = e.CommandArgument.ToString();
DataRow drFile = Contract_TransportFilesAdapter.GetDataByInvoiceNoKey(invoiceNo).Rows[0];
string strFileName = invoiceNo + "_运单";
Response.Buffer = true;
Response.Clear();
Response.ContentType = drFile["FILE1_TYPE"].ToString();
Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(strFileName));
Response.BinaryWrite((Byte[])drFile["FILE1"]);
Response.End();
但会出现文件名乱码情况,而且只回来浏览器里出现。FILE1_TYPE是数据库表的字段:纪录是:image/gif 或者application/pdf等等作为参考,以下是我上传写的代码:
string strType1 = UploadFile1.ContentType;
byte[] byteData1 = new byte[intLen1]; Stream objStream1 = UploadFile1.InputStream; objStream1.Read(byteData1, 0, intLen1);
rowFile.INVOICENO = invoriceNo;
rowFile.FILE1 = byteData1;
rowFile.FILE1_TYPE = strType1;
rowFile.FILE1_LENGTH = intLen1;
bool blnNew = new ContractData().AddTransportFile(rowFile, guidUserId);//Insert进数据库
string invoiceNo = e.CommandArgument.ToString();
DataRow drFile = Contract_TransportFilesAdapter.GetDataByInvoiceNoKey(invoiceNo).Rows[0];
string strFileName = invoiceNo + "_运单";
Response.Buffer = true;
Response.Clear();
Response.ContentType = drFile["FILE1_TYPE"].ToString();
Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(strFileName));
Response.BinaryWrite((Byte[])drFile["FILE1"]);
Response.End();
但会出现文件名乱码情况,而且只回来浏览器里出现。FILE1_TYPE是数据库表的字段:纪录是:image/gif 或者application/pdf等等作为参考,以下是我上传写的代码:
string strType1 = UploadFile1.ContentType;
byte[] byteData1 = new byte[intLen1]; Stream objStream1 = UploadFile1.InputStream; objStream1.Read(byteData1, 0, intLen1);
rowFile.INVOICENO = invoriceNo;
rowFile.FILE1 = byteData1;
rowFile.FILE1_TYPE = strType1;
rowFile.FILE1_LENGTH = intLen1;
bool blnNew = new ContractData().AddTransportFile(rowFile, guidUserId);//Insert进数据库
{
string FullFileName = "d:\\111.zip";
FileInfo DownloadFile = new FileInfo(FullFileName);
Response.Clear();
Response.ClearHeaders();
Response.Buffer = false;
Response.ContentType = "application/octet-stream";
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(DownloadFile.FullName, System.Text.Encoding.UTF8));
Response.AppendHeader("Content-Length", DownloadFile.Length.ToString());
Response.WriteFile(DownloadFile.FullName);
Response.Flush();
Response.End();
}