2012-03-01 15 views
6

拡張子が*.icoの画像を表示したいのですが、それにはStreamを使用します。しかし、私には問題があります。ストリームを使用して画像を表示する* .ico

拡張 *.jpg*.bmp ... OKイメージ・ショーで

しかし*.ico、それはここで

は表示されません。私のコードです:

private void OutputStream(string fileName) 
    { 
     try 
     { 
      Stream dataStream = null; 

       SPSecurity.RunWithElevatedPrivileges(delegate() 
       { 
        SPFile spFile = web.GetFile(fileName); 
        dataStream = spFile.OpenBinaryStream(); 
        this.HandleOutputStream(dataStream); 
       }); 

     } 
     catch (System.Threading.ThreadAbortException exTemp) 
     { 
      logger.Error("KBStreamPicture::OutputStream", exTemp); 
     } 
     catch (Exception ex) 
     { 
      //System.Diagnostics.Debug.Write("OutputStream::" + ex); 
      logger.Error("KBStreamPicture::OutputStream", ex); 
     } 
    } 

private void HandleOutputStream(Stream dataStream) 
    { 
     const int bufferSize = 16384; //16KB 

     using (Stream file = dataStream) 
     { 
      if (file != null) 
      { 
       this.Page.Response.Clear(); 
       this.Page.Response.Cache.SetCacheability(System.Web.HttpCacheability.Private); 
       this.Page.Response.Cache.SetExpires(DateTime.Now.AddMinutes(20)); //only cache 20 minutes 
       byte[] buffer = new byte[bufferSize]; 
       int count = file.Read(buffer, 0, bufferSize); 

       while (count > 0) 
       { 
        if (this.Page.Response.IsClientConnected) 
        { 
         this.Page.Response.OutputStream.Write(buffer, 0, count); 
         count = file.Read(buffer, 0, bufferSize); 
        } 
        else 
        { 
         count = -1; 
        } 
       } 
       this.Page.Response.End(); 
      } 
     } 
    } 

に私を助けてくださいその問題を解決してください。

+0

コードは(奇妙なSPセキュリティのオーバーライド、および不明瞭彼らはurlですでにアクセスできる必要があるとき、なぜあなたは手でファイルをダウンストリームしようとすると、OKに見えます... )。サーバ上でファイルのストリームを取得したり、ブラウザでレンダリングする際に問題がありますか(私はICOがIMGタグとしてレンダリングするとは思わない) –

答えて

4

ResponseContentTypeプロパティを設定していません。 ContentTypeimage/x-iconに設定してください(「正しい」コンテンツタイプはimage/vnd.microsoft.iconであるかもしれませんが、this postはそのタイプの問題が発生する可能性があると思われます)。

コードのようなものになります。

this.Page.Response.Clear(); 
this.Page.Response.Cache.SetCacheability(System.Web.HttpCacheability.Private); 
this.Page.Response.Cache.SetExpires(DateTime.Now.AddMinutes(20)); 
this.Page.Response.ContentType = "image/x-icon"; 
+0

ありがとうございました。私は私のために働いた。 – user1186850

+0

うまくいけば答えとして 'user'マーク – Dotnet

+0

@ user1186850うれしいわよ! – rsbarro

関連する問題