是的 - 您必须在将“文件”发送给用户之前对其进行操作。
在您的方法DownloadOfflineAuditSheetEditor
中,您可以调用一个新方法来读取当前文件,从数据库中获取内容,然后写入文件或新文件,例如:
public void GenerateRealTimeContent()
{
var path = Server.MapPath("~/thefile.html");
var dbContent = Database.GetContent(); // returns the <select> Options
string[] lines = System.IO.File.ReadAllLines(path);
StringBuilder sb = new StringBuilder();
foreach (var line in lines)
{
if (line == "CONTENT WHERE YOU WANT TO EDIT")
{
SB.AppendLine(dbContent);
}
SB.AppendLine(line);
}
// code to write to your file
}
然后在你原来的功能做:
public void DownloadOfflineAuditSheetEditor(object s, EventArgs e)
{
GenerateRealTimeContent();
Response.AppendHeader("content-disposition", "attachment; filename=thefile.html");
Response.WriteFile(Server.MapPath("~/thefile.html"), true);
Response.End();
}
http://msdn.microsoft.com/en-us/library/ezwyzy7b.aspx - Reading from a file
http://msdn.microsoft.com/en-us/library/aa287548(v=vs.71).aspx - Write to a file