從數據庫檢索文件我已經使用下面的linq查詢下載efile,但我有功能下載(Efile)中的問題無效參數。 我已經看到了一些使用數據表下載的地方。我喜歡這樣做,而不使用數據表,但我不知道如何?無效的參數
the fields of table tblfile is like below.
fileid(int), FileName (varchar(50)), ContentType (varchar(50)), Data varbinary(MAX)
請問有什麼問題。
protected void LinkButton1_Command(object sender, CommandEventArgs e)
{
if (e.CommandName == "Download")
{
_DataContext = new EDMSDataContext();
//you can get your command argument values as follows
string FileId = e.CommandArgument.ToString();
int _FileId = Convert.ToInt32(FileId);
var Efile = from ef in _DataContext.tblFiles
where ef.FileId == _FileId
select ef;
if (Efile != null)
{
download(Efile);
}
}
}
private void download (tblFile Efile)
{
Byte[] bytes = (Byte[])Efile.Data.ToArray();
Response.Buffer = true;
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = Efile.ContentType.ToString();
Response.AddHeader("content-disposition", "attachment;filename="
+ Efile.FileName.ToString());
Response.BinaryWrite(bytes);
Response.Flush();
Response.End();
}
感謝錯誤刪除,但它似乎下載功能不起作用,沒有下載發生 – masoud