Tech
Forums
Jobs
Books
Events
Videos
Conference
Annual Conference
Bcrypt
Ai Conference
Live
More
Interviews
Certification
Training
Career
Members
News
Blogs
Post
An Article
A Blog
A Video
An Ebook
An Interview Question
Register
Login
2
Reply
document not being opened
Cassie Mod
8 years ago
275
Reply
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();
//Response.End();
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();
}
Post
Reset
Cancel
Answers (
2
)
Next Recommended Forum
How to convert list to string
Update&Delete Records in a C# DataGrid using .txt file