0

ファイルをバイナリ形式で保存するタイプのイメージのデータベースにフィールドがあります。

ここで、ユーザーがそのファイルをダウンロードできる場所をユーザーに提供したいと考えています。バイト配列オブジェクトにファイルデータがあります。開いている保存ダイアログボックスをユーザーに表示するにはどうすればよいですか?

4

3 に答える 3

0

これは、データベースから blob 画像を表示する例です。画像を表示する代わりにダウンロード用のファイルを提供するように変更できます (id はデータベース内の画像ファイル ID です)。

void  CreateImage(string id)
{
    // Connection string is taken from web.config file.
    SqlConnection _con = new SqlConnection(
      System.Configuration.ConfigurationSettings.AppSettings["DB"]);

    try
    {
        _con.Open();
        SqlCommand _cmd = _con.CreateCommand();
        _cmd.CommandText = "select logo from" + 
                           " pub_info where pub_id='" + 
                           id + "'";
        byte[] _buf = (byte[])_cmd.ExecuteScalar();

        // This is optional
        Response.ContentType = "image/gif";

        //stream it back in the HTTP response
        Response.BinaryWrite(_buf);


    }
    catch
    {}
    finally
    {
        _con.Close();

    }
}
于 2012-10-30T08:17:25.543 に答える
0

これを確認してみてください:ヘッダー付きの画像を提供するashxファイルハンドラーを作成します:

Content-Type: application/force-download
于 2012-10-30T08:18:13.843 に答える
0

どうですか:

//using System.Net;   
WebClient wc = new WebClient();

OpenFileDialog ofd = new OpenFileDialog();
if(ofd.ShowDialog() == DialogResult.OK)
   wc.DownloadFile("http://website.net/image.jpg", ofd.FileName);

編集:

//using System.IO;
MemoryStream ms = new MemoryStream(array);
Bitmap bmp = new Bitmap(ms);
bmp.Save("C:\\image.bmp");
于 2012-10-30T08:18:45.050 に答える