Showing posts with label aspx. Show all posts
Showing posts with label aspx. Show all posts

Sunday, March 25, 2012

Create a PDF file directly to disk?

Hello all,

I use Reporting Services and an aspx page to create a PDF file. I need to save the file directly to a disk file with a name, without asking the user if he want to open or to save it. I'm using the folowing command:

Response.WriteFile("http://" & System.Environment.MachineName & "/ReportServer?%2fReportsApp%2fRptFSUnicoR&rs%3aCommand=Render&rs%3aFormat=PDF&MyID=" & IDFun,True)

Any idea how I do that?

Regards

HttpResponse.WriteFile requires either an absolute or virtual path to a sever-local filesystem location. So, referencing the URL of the report server won't work.

Also, I don't think you'll be able to bypass any browser's download prompt dialog without employing some sort of trusted control to do the HTTP request and file saving for you behind the scenes. SoftArtisans XFile is one such product that can do this.

-Chris

|||

Hi Chris,

Thank you for your answer. I'm afraid I will have to think in another solution.

As Report is generated from Reporting Services I thought I could have another parameter to force the "save" at the time I render the Report.

Best regards

sql

Monday, March 19, 2012

CR10 web viewer width 100%

Hello,
I'm trying to set my CrystalReportViewer to 100% of page width in ASP.NET. When I set the Width property on the control in the ASPX page itself, the viewer renders itself correctly when the page first loads, but on each postback the "%" is changed to "px" causing the viewer to be only 100 pixels wide.

I can apparently get around that by setting the width to Unit.Percentage(100) on every Page_Load event. Then the viewer appears as I expect with 100% width everytime I navigate pages, search, or export.

My problem is this workaround doesn't seem to work for the group tree. When I toggle the group tree, the two divs that get rendered are of width 14px and 86px (which add up to 100px).

Any ideas how I can get around this bug?

Thanks,
JamesI have a lousy solution but it seems to work (this is C# code but same should apply to VB):
public class MyCrystalReportViewer : CrystalDecisions.Web.CrystalReportViewer
{
protected override void Render(HtmlTextWriter output)
{
string renderedControl = string.Empty;

// Render the control to a string builder
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
HtmlTextWriter htw = new HtmlTextWriter(sw);
base.Render(htw);

// Extract the string for processing
renderedControl = sb.ToString();

// Replace certain strings in the group tree div style tag
// Be sure to check for all indices along the way and just do nothing if things aren't found.
int groupTreeIndex = renderedControl.IndexOf("<div class=\"crgrptr\"");
if ( groupTreeIndex != -1 )
{
int groupTreeStyle = renderedControl.IndexOf("style=\"",groupTreeIndex);
if ( groupTreeStyle != -1 )
{
int groupTreeStyleEnd = renderedControl.IndexOf("\"",groupTreeStyle+7);
if ( groupTreeStyleEnd != -1 )
{
string groupTreeStyleTag = renderedControl.Substring(groupTreeStyle+7,groupTreeStyleEnd-groupTreeStyle-7);
renderedControl = renderedControl.Substring(0,groupTreeStyle+7)
+ "display:inline;" + groupTreeStyleTag.Replace("width:14px","width:14%").Replace("position:absolute","position:static")
+ renderedControl.Substring(groupTreeStyleEnd);
}
}
}

// Replace certain strings in the page div style tag
// Be sure to check for all indices along the way and just do nothing if things aren't found.
int pageIndex = renderedControl.IndexOf("<div class=\"crystalstyle\"");
if ( pageIndex != -1 )
{
int pageStyle = renderedControl.IndexOf("style=\"",pageIndex);
if ( pageStyle != -1 )
{
int pageStyleEnd = renderedControl.IndexOf("\"",pageStyle+7);
if ( pageStyleEnd != -1 )
{
string pageStyleTag = renderedControl.Substring(pageStyle+7,pageStyleEnd-pageStyle-7);
renderedControl = renderedControl.Substring(0,pageStyle+7)
+ "display:inline;" + pageStyleTag.Replace("width:86px","width:86%").Replace("position:absolute","position:static")
+ renderedControl.Substring(pageStyleEnd);
}
}
}

// Now output the reformatted HTML of the control
output.Write(renderedControl);
}
}