AsyncFileUpload AJAX コントロールを使用して、LINQ to SQL を使用して SQL Server データベースの列にファイルをアップロードしました。データベースからドキュメントを取得し、ユーザーが LINQ to SQL を使用して [名前を付けて保存] ダイアログ ボックスを使用してローカル ドライブに保存できるようにするにはどうすればよいですか? これは ASP.NET Web アプリケーションです。DocumentFileContent データベース列は、Image SQL Server データ型です。ありがとう
1 に答える
2
Web フォームでの最善の方法は、HTTP ハンドラーを使用することです。
image
データ型の DB クエリは、 byte[]
.
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;
}
}
}
于 2010-10-26T22:01:55.240 に答える