2011-06-24 62 views
3

私のプロジェクトで問題があります。 コンテンツをダウンロードするためのコードがあります:.doc、.zipなどC#Asp Net Chromeでのダウンロードで問題が発生する12

バージョン12のChromeアップデートが完了するまで、ブラウザにエラーメッセージ "ダウンロード中断"が表示されていました。

私は既に他のブラウザ(Chrome 11、FF、IE8)でテストしており、すべて正常に動作します。

コードサンプルは次のとおりです。

HttpContext.Current.Response.Clear(); 
HttpContext.Current.Response.AppendHeader("Content-Type", "application/msword"); 
HttpContext.Current.Response.AppendHeader("Content-disposition", "attachment; filename=" + filename + ".doc"); 
HttpContext.Current.Response.AppendHeader("Content-Transfer-Encoding", "binary"); 
HttpContext.Current.Response.Write(strBody); 
HttpContext.Current.Response.Flush(); 
HttpContext.Current.Response.Close(); 

誰かが起こっまたはどのように私はそれを修正することができますすることができます知っていますか?

ps。申し訳ありませんが私の英語、私はブラジルです:)

+0

私は 'strBody'が文字列であると仮定しています。 content-transfer-encodingをバイナリに設定しているので、 'Response.BinaryWrite(byteArray)'を使うか、その行を削除する必要があります。 –

+0

どこから来たファイル名は、私はそれがデータベースフィールドであることを意味します –

答えて

1

this forumの回答によると、Response.End()を追加する問題を解決しました。あなたのケースでは

、それは私がこのコードでSQL Serverデータベースからの私のバイナリデータを取得していますし、それはすべてのブラウザで動作している

HttpContext.Current.Response.Write(strBody); 
HttpContext.Current.Response.Flush(); 
HttpContext.Current.Response.End(); 
HttpContext.Current.Response.Close(); 
+0

私はそれを試しましたが、私のために働いていません。 –

0

だろう。

 DataTable table = SiteFileAccess.GetDataByFileID(fileId); 
     byte[] b = (byte[])table.Rows[0]["FileData"]; 
     Response.Clear(); 
     Response.AddHeader("Content-Disposition", "attachment; filename=" + table.Rows[0]["FileName"].ToString()); 
     Response.AddHeader("Content-Length", b.Length.ToString()); 
     Response.ContentType = "application/octet-stream"; 
     Response.BinaryWrite(b); 
     Response.Flush(); 
     Response.End(); 

あなたの必要に応じて修正してください。さらに詳しい情報が必要な場合は教えてください

0

文字列applicationName = Session ["ApplicationName_UtilityDetail"] ToString();

HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create(Session["DownloadLink_UtilityDetail"].ToString()); 
    HttpWebResponse objResponse = (HttpWebResponse)objRequest.GetResponse(); 
    int bufferSize = 1; 
    Response.Clear(); 
    Response.ClearHeaders(); 
    Response.ClearContent(); 
    Response.AppendHeader("Content-Disposition:", "attachment; filename=" + applicationName + ".zip"); 
    Response.AppendHeader("Content-Length", objResponse.ContentLength.ToString()); 
    Response.ContentType = "application/download"; 
    byte[] byteBuffer = new byte[bufferSize + 1]; 
    MemoryStream memStrm = new MemoryStream(byteBuffer, true); 
    Stream strm = objRequest.GetResponse().GetResponseStream(); 
    byte[] bytes = new byte[bufferSize + 1]; 
    while (strm.Read(byteBuffer, 0, byteBuffer.Length) > 0) 
    { 
     Response.BinaryWrite(memStrm.ToArray()); 
     Response.Flush(); 
    } 
    Response.Close(); 
    Response.End(); 
    memStrm.Close(); 
    memStrm.Dispose(); 
    strm.Dispose(); 
関連する問題