Linq to sql 从数据库检索MS Word文档并在本地保存

Linq to sql 从数据库检索MS Word文档并在本地保存,linq-to-sql,dialog,save-as,Linq To Sql,Dialog,Save As,我使用AsyncFileUpload AJAX控件使用LINQtoSQL将文件上载到SQLServer数据库中的列。如何从数据库检索文档,并允许用户使用LINQ to SQL使用另存为对话框保存到本地驱动器?这是ASP.NET web应用程序。DocumentFileContent数据库列是图像SQL Server数据类型。谢谢在webforms中,最好的方法是使用HTTP处理程序 对图像数据类型的DB查询将映射到字节[] public class Document : IHttpHandler

我使用AsyncFileUpload AJAX控件使用LINQtoSQL将文件上载到SQLServer数据库中的列。如何从数据库检索文档,并允许用户使用LINQ to SQL使用另存为对话框保存到本地驱动器?这是ASP.NET web应用程序。DocumentFileContent数据库列是图像SQL Server数据类型。谢谢

在webforms中,最好的方法是使用HTTP处理程序

图像
数据类型的DB查询将映射到
字节[]

public class Document : IHttpHandler
{
    public void ProcessRequest(HttpContext context)
    {
        using (SQLConnection con = new SQLConnection)
        {
            SqlCommand command = new SqlCommand("SELECT imagefield FROM table", con);
            connection.Open();

            SqlDataReader reader = command.ExecuteReader();
            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    context.Response.ContentType = "application/msword";
                    context.Response.BinaryWrite(reader["imagefield"]);
                }
            }
            reader.Close();
        }
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }
}