为了从数据库中检索文件,我使用了下面的 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();
}