Hello,
I am trying to use XAF as an administration tool to store PDF documents in the database using the FileData table. My hope is that there is a way to extract that document when a user clicks on a hyperlink (preferably) or a button and opens that document in a new tab in the browser. The website this needs to display in is a standard .net web application and not an XAF website.
I was able to create the following but the Content Field apparently has additional information at the beginning of the file and corrupts the PDF when created. Also it downloads instead of opening in a new browser.
Thanks for your help!
var btn = (ASPxButton)sender;
var arg = btn.CommandArgument;
string connetionString = myConnection ;
string sql = "SELECT [Content] FROM [dbo].[FileData] WHERE [FileName] = '" + arg + "'";
var cnn = new SqlConnection(connetionString);
try
{
cnn.Open();
var cmd = new SqlCommand(sql, cnn);
var reader = cmd.ExecuteReader();
while (reader.Read())
{
Response.Buffer = true;
Response.Charset = "";
Response.AppendHeader("Content-Disposition", "attachment; filename=" + arg);
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/pdf";
Response.BinaryWrite(reader.GetValue(1) as byte[]);
Response.Flush();
Response.End();
}
reader.Close();
cmd.Dispose();
cnn.Close();
}
finally
{
cnn.Close();
}