长期潜伏者第一次海报。与.Net / Linq 合作了几年,所以我确定我在这里遗漏了一些东西。经过无数小时的研究,我需要帮助。我的代码基于 https 的建议:http: //damieng.com/blog/2010/01/11/linq-to-sql-tips-and-tricks-3
以下代码当前将存储在 sql 数据库中的选定文件(pdf、doc、png 等)保存到 C:\temp。效果很好。我想更进一步。我可以让浏览器提示而不是自动将其保存到 c:\temp,以便他们可以将其保存到所需的位置。
{
var getFile = new myDataClass();
//retrieve attachment id from selected row
int attachmentId = Convert.ToInt32((this.gvAttachments.SelectedRow.Cells[1].Text));
//retrieve attachment information from dataclass (sql attachment table)
var results = from file in getFile.AttachmentsContents
where file.Attachment_Id == attachmentId
select file;
string writePath = @"c:\temp";
var myFile = results.First();
File.WriteAllBytes(Path.Combine(writePath, myFile.attach_Name), myFile.attach_Data.ToArray());
}
因此,我可以代替使用 File.WriteAllBytes 来获取从我的 linq 查询(myFile)返回的数据并将其传递给会提示用户保存文件的东西吗?)。这个返回的对象可以与 response.transmitfile 一起使用吗?非常感谢。