Crystal Reports - export to pdf in MVC - asp.net

I have integrated the below code in my application to generate a 'pdf' file using crystal reports in MVC project.
However, after the request is processed, i get to see only 2 pages in the pdf file while my 'data' returns more than 2 records.
Also, the pdf isn't rendered as soon as the page is processed but instead i have to refresh atleast once, then the pdf is rendered on the browser.
using CrystalDecisions.CrystalReports.Engine;
public FileStreamResult Report()
{
ReportClass rptH = new ReportClass();
List<sampledataset> data = objdb.getdataset();
rptH.FileName = Server.MapPath("[reportName].rpt");
rptH.Load();
rptH.SetDatabaseLogon("un", "pwd", "server", "db");
rptH.SetDataSource(data);
Stream stream = rptH.ExportToStream
(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
stream.Seek(0, System.IO.SeekOrigin.Begin);
return new FileStreamResult(stream, "application/pdf");
}
I took the code from here in SO but modified it like above.
TIA.
EDIT: This works on Firefox, not in IE7.

I finally found the solution here on SO. It had nothing to do with MVC but the way IE treats popup window.

Related

How to load devexpress xtrareport from file and connect data

I use devexpress xtrareports v.15 for winforms in my project.
I have invoice report. It has some text fields inside and one list. I connect data to sources in report ctor:
public InvoiceReport(InvoiceCommonData icd, List<ReportPosition> positions)
{
InitializeComponent();
this.ReportCommonDataSource.DataSource = icd;
this.positionsList.DataSource = positions;
}
When I print report as it was created in Visual Studio data is connected in right way.
But I need to load different layouts for this report. I store report layout as repx file and try to load it from file at runtime:
InvoiceReport report = new InvoiceReport(model.GetCommonData(), model.GetPositions());
var filename = "D://InvoiceReport.repx";
report.LoadLayout(filename);
When I print report I see that common data (icd) was bound and is printed but list (positions) was not bound and it is empty table instead of real data.
Question is how to load xtrareport layout from file and save all data connections?
but i think u can try to replace connection of default repx file to your main connection becouse when we create repx file from report designer that time we set connection and repx save as default when we try to preview report with viewer file get default save connection so try to replace connection from required sql connection .
like if (((DevExpress.DataAccess.Sql.SqlDataSource)devxReport.DataSource).ConnectionParameters != null) //change if connection exists in report
{
((DevExpress.DataAccess.Sql.SqlDataSource)devxReport.DataSource).ConnectionParameters = null;
}
((DevExpress.DataAccess.Sql.SqlDataSource)devxReport.DataSource).ConnectionParameters =
new DevExpress.DataAccess.ConnectionParameters.CustomStringConnectionParameters(sqlConnectionString);

Printing silently from Spring MVC/Jasper Application

This is very abstract question.
I'm working on a Spring MVC Web Application which has to deal with lot of invoice printing continuously. Currently When the invoice is saved, the spring controller delegates the invoice id to the jasper pdf generation service which prepares the pdf. After the pdf gets downloaded, the user manually prints it.
I need a way to print the invoice silently when the user saves the invoice.
Any ideas?
Since you are exporting to PDF it is possible. You need to add a JRPdfExporterParameter.PDF_JAVASCRIPT parameter to your JRPdfExporter instance with the value "this.print({bUI: true,bSilent: false,bShrinkToFit: true});". For Example:
protected static byte[] exportReportToPdf(JasperPrint jasperPrint) throws JRException{
JRPdfExporter exporter = new JRPdfExporter();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, baos);
exporter.setParameter(JRPdfExporterParameter.PDF_JAVASCRIPT, "this.print({bUI: true,bSilent: false,bShrinkToFit: true});");
exporter.exportReport();
return baos.toByteArray();
}
This actually adds the JavaScript to the PDF. When the PDF is opened it is ran, and will send it the print queue. It should be noted that this should be used sparingly as it is not generally considered to be nice to do this automatically for your users. When I have used it in an app, we had to buttons for each report. An Export button, that does not contain the JavaScript, and a Print button that did. That way users that wanted it to just print it would do so, and those that wanted a digital copy had that also.

API (Service) to work for both Windows Phone and Website

I created(in last stage) a ASP.NET website which requires database communications, So we created WCF services to connect to the database. If there is a Select statement those service returns DataTable.
Services are working fine and website also working fine
At the time of API creation i don't know that windows phone sdk does not support the DataTables.
I read some where that Windows Phone SDK doesn't support DataTable, i checked in my Visual Studio also there is no class called DataTable in System.Data namespace.
I am new to Windows Phone.
But now we want to create a WINDOWS PHONE APP which also works same as Website, so we want to use the existing API(WCF Service).
is there is any way to accomplish this task. most of the methods return type is DataTable.
we don't want to create two API's(means services). What should I do?
How to create a Service which works for both Windows Phone and Website.
we are ready to change the change the API and according to that ready to update Website also?
thanks
Just changed the API to return Stream instead of DataTable
System.IO.StringWriter reader = new System.IO.StringWriter();
dt.WriteXml(reader, XmlWriteMode.WriteSchema);//dt is datatable
return reader;
in website small minor changes, reading the stream and assign it to a datatable
StringReader xmlReader = new StringReader(stream);
DataTable dt = new DataTable();
dt.ReadXml(xmlReader);
Update:
This approach is not suggestible(this was my first web service application), I suggest to use JSON/XML responses(with returning DTOs) instead of returning DataTable..
Following links might land you in right direction.
http://www.codeproject.com/Articles/105273/Create-RESTful-WCF-Service-API-Step-By-Step-Guide
http://mono.servicestack.net/ServiceStack.Hello/
Not sure why you used datatable. Do you mean dataset?
They are all XML under the covers. Try parsing them. Try something like this:
var resultNewDataSet = XElement.Parse(xmlContent);
var result = resultNewDataSet.Descendants("Table")
.Select(t => new
{
aaa = t.Descendants("aaa").First().Value,
bbb = t.Descendants("bbb").First().Value
});
foreach (var res in result)
{
System.Diagnostics.Debug.WriteLine("aaa: " + res.aaa + " / bbb: " + res.bbb);
}

Silverlight MediaElement refusing to play audio

I am having the hardest time figuring this problem out. I have a Silverlight 4 application that loads audio and video files from URLs. The URLs are the same domain as the application is hosted on and it works great for video.
The URLs are actually asp.net mvc controllers that are responsible for reading the file from a shared location on and the server and serving back a filestream. The URLs look something like this:
http://localhost:31479/CourseMedia?path=\omnisandbox1\ILMSShare2\Demo-Fire+Behavior\media\Disclaim.wma&encrypted=False&id=00000000-0000-0000-0000-000000000000
If I put the URL directly into the browser the file loads and plays in windows media player just fine, and if I use a separate test silverlight project to load the url it also works, but for the life of me I can not get it to work properly in my main project.
This is the routine I use to actually do the source setting:
protected void SetPlayerURL(MediaElement player, string url)
{
if (player != null && url.Length > 0)
{
player.ClearValue(MediaElement.SourceProperty);
player.Source = new Uri(this.Packet.GetMediaUrl(url, false, Guid.Empty));
}
}
and the GetMediaURL function simply builds the URL format seen above:
public string GetMediaUrl(
string path,
bool encrypted,
Guid key)
{
StringBuilder builder = new StringBuilder();
builder.AppendFormat("http://{0}/CourseMedia?path={1}&encrypted={2}&id={3}",
this.Host,
System.Windows.Browser.HttpUtility.UrlEncode(path),
encrypted,
key);
return builder.ToString();
}
The request to the controller is never made for the media when it is audio. Seems odd to me as this exact code works fine for video. The MediaElement state never leaves "Closed" and the CurrentStateChanged,, MediaOpened, and MediaFailed events are never triggered.
I am at a loss!
Try setting ScrubbingEnabled of the MediaElement to false, there were some problems with Framework version 3.5 and audio and the workaround was setting that to false. Might be worth trying.
Also try capturing BufferingStarted, BufferingEnded, MediaEnded along with your MediaFailed and MediaOpened events. I'm curious if it is a buffering issue.

XML Caching issue in FLex

private function loadGallery():void {
theSend.url = "http://localhost/userMana/file.xml";
theSend.send();
}
I am calling this XML in Flex Tree and its works fine, but when after an update in XML it does not update back in my TREE unless i compile my flex builder again.
I usually do this by appending the time to the XML url:
var now:Date = new Date();
theSend.url = "http://localhost/userMana/file.xml?" + now.getTime();
theSend.send();
non-cached every time.
You could try flushing your local cache after you update. Stopping and starting "World Wide Web Publishing Service" (which is what it's called under Vista; XP will have a different name) should do it.

Resources