I want to show an image with the extension *.ico
, and I use Stream
for this. But I have a problem.
With the extension *.jpg
, *.bmp
... The image is displayed normally, but *.ico
, it does not show
Here is my code:
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) {
and
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(); } } }
Please help me solve this problem.
source share