Cassie Mod

Cassie Mod

  • NA
  • 631
  • 18k

document not being opened

Apr 5 2016 12:01 PM
hi, I have the following problem. I should be able to open a document based on the binary data from the SQL server. However, I don't get an error, but the document isn't opened asswel. so what am I missing or doing wrong ?
 
  1. protected void LinkButtonOpenFile_OnClick(Object sender, EventArgs e)  
  2.        {  
  3.            using (var connection = DatabaseLayer.OpenConnection())  
  4.            using (var transaction = connection.BeginTransaction())  
  5.            {  
  6.                try  
  7.                {  
  8.                    LinkButton link = (LinkButton)sender;  
  9.                    var FileName = link.Text;  
  10.                    var extention = Path.GetExtension(FileName);  
  11.                    var attachmentID = ProjectAttachmentLogic.getIdByprojectIdAndFileName(sender, connection, transaction, ViewState["projectID"], FileName);  // works fine
  12.                    var document = ProjectAttachmentLogic.getVarBinaryDataById(sender, connection, transaction, attachmentID, FileName);  // works fine
  13.                      
  14.                    var stream = new MemoryStream(document);  
  15.                    Response.Clear();  
  16.                    Response.ClearHeaders();  
  17.                    Response.ClearContent();  
  18.                    Response.Buffer = false;  
  19.                    Response.ContentType = ProjectAttachmentLogic.getContentType(extention);  // works fine
  20.                    Response.BinaryWrite(stream.ToArray());  
  21.                    Response.OutputStream.Write(stream.ToArray(), 0, stream.ToArray().Length);  
  22.                    Response.OutputStream.Flush();  
  23.                    //Response.End();  
  24.                    HttpContext.Current.Response.Flush();  
  25.                    HttpContext.Current.Response.SuppressContent = true;  
  26.                    HttpContext.Current.ApplicationInstance.CompleteRequest();  
  27.                    transaction.Commit();  
  28.                }  
  29.                catch (ThreadAbortException ex)  
  30.                {  
  31.                    string Err = ex.Message.ToString();  
  32.                    throw;  
  33.                }  
  34.                catch (Exception ex)  
  35.                {  
  36.                    string Err = ex.Message.ToString();  
  37.                    throw;  
  38.                }  
  39.                finally  
  40.                {  
  41.                    HttpContext.Current.Response.SuppressContent = true;  
  42.                    HttpContext.Current.ApplicationInstance.CompleteRequest();  
  43.                }  
  44.            }  
  45.            Response.End();  
  46.        }  
 



Answers (2)