c#實現文件寫入數據表/以二進制流保存到數據庫,並實現下載


上傳:

1、上傳文件先保存到服務器   File.SaveAs(path)

2、sql(文件和sql在一個服務器上)進行保存操作:

insert into File(filename,filebody)

values('長大了是否.txt',(SELECT * FROM OPENROWSET(BULK '" + path + "',SINGLE_BLOB) AS x))

 

下載:

if (reader.Read())


Response.Clear();
String strFileName = reader["oldname"].ToString();
Response.ContentType = "APPLICATION/OCTET-STREAM";
Response.AddHeader("content-disposition", "attachment;filename=" + HttpUtility.UrlEncode(strFileName));
Response.Buffer = true;
Response.BinaryWrite((byte[])reader["filecontent"]);


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM