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 ?
- protected void LinkButtonOpenFile_OnClick(Object sender, EventArgs e)
- {
- using (var connection = DatabaseLayer.OpenConnection())
- using (var transaction = connection.BeginTransaction())
- {
- try
- {
- LinkButton link = (LinkButton)sender;
- var FileName = link.Text;
- var extention = Path.GetExtension(FileName);
- var attachmentID = ProjectAttachmentLogic.getIdByprojectIdAndFileName(sender, connection, transaction, ViewState["projectID"], FileName); // works fine
- var document = ProjectAttachmentLogic.getVarBinaryDataById(sender, connection, transaction, attachmentID, FileName); // works fine
-
- var stream = new MemoryStream(document);
- Response.Clear();
- Response.ClearHeaders();
- Response.ClearContent();
- Response.Buffer = false;
- Response.ContentType = ProjectAttachmentLogic.getContentType(extention); // works fine
- Response.BinaryWrite(stream.ToArray());
- Response.OutputStream.Write(stream.ToArray(), 0, stream.ToArray().Length);
- Response.OutputStream.Flush();
-
- HttpContext.Current.Response.Flush();
- HttpContext.Current.Response.SuppressContent = true;
- HttpContext.Current.ApplicationInstance.CompleteRequest();
- transaction.Commit();
- }
- catch (ThreadAbortException ex)
- {
- string Err = ex.Message.ToString();
- throw;
- }
- catch (Exception ex)
- {
- string Err = ex.Message.ToString();
- throw;
- }
- finally
- {
- HttpContext.Current.Response.SuppressContent = true;
- HttpContext.Current.ApplicationInstance.CompleteRequest();
- }
- }
- Response.End();
- }