TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Cassie Mod
NA
488
70.2k
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 ?
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();
}
Reply
Answers (
2
)
How to convert list to string
Update&Delete Records in a C# DataGrid using .txt file