データベースからファイルを取得するために、efile をダウンロードするために以下の linq クエリを使用しましたが、関数 download(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();
}