Hi Guys,
We are using below code for rendering PDF content in custom .aspx page( in Response.OutputStream.Write)SharePoint 2010 from Document Library. But its taking time to render the data, do we have any other optimized way to render the PDF content in SharePOint page from C#.
Please suggest.
string ReportDocLibrary = "Test"
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(SPContext.Current.Site.Url))
{
using (SPWeb web = site.OpenWeb())
{
SPQuery query = new SPQuery();
string dcry= @"<Where><Eq><FieldRef Name='RptID' /><Value Type='Text'>" + reptId + "</Value></Eq></Where><OrderBy><FieldRef Name='Modified' Ascending='FALSE' /></OrderBy>";
query.Query = dcry;
SPList docLibrary = web.Lists["Test"];
SPFolder searchFolder = docLibrary.RootFolder.SubFolders[folderName];
if (searchFolder.SubFolders[selectedMonth + selectedYear] != null)
{
SPFolder monthFolder = searchFolder.SubFolders[selectedMonth + selectedYear];
query.Folder = monthFolder;
query.ViewAttributes = "Scope='Recursive'";
SPListItemCollection itemColn = docLibrary.GetItems(query);
if (itemColn.Count > 0)
{
SPListItem listItem = itemColn[0];
SPFile docFile = listItem.File;
byte[] buffer;
buffer = docFile.OpenBinary();
string contentType = string.Empty;
contentType = "application/pdf";
Response.ContentType = contentType;
Response.AddHeader("content-disposition", "inline; filename=MyPDF.PDF");
Response.OutputStream.Write(buffer, 0, buffer.Length);
Response.OutputStream.Flush();
Response.OutputStream.Close();
Response.Flush();
Response.End();