How to access the properties and parts of an SSRS report at runtime - asp.net

I'm using the ReportViewer control to display a server report in an ASP.NET page and I'm looking for a way to get the report into an object that I can then read and/or modify.
This kind of thing:
var rw = report.Width;
var t = ((Chart)report.Body.Item[3]).Title;
Is there a way, or am I stuck with parsing the XML file?
ETA:
I'm beginning to think I will need to access the XML file but I can't find out how to download that from the server, modify it (in memory) and then send it to the ReportViewer control.
ETA2:
Here's how to download the report definition (clean up left out for brevity):
// Download the report
var rs = new ReportingService2010();
rs.UseDefaultCredentials = true;
var reportDefinition = rs.GetItemDefinition("/DashboardReports/MyChart");
// Convert to XML
var ms = new MemoryStream(reportDefinition);
var doc = new System.Xml.XmlDocument();
doc.Load(ms);
// To load the stream into the report viewer
stream.Position = 0; // needed because we used the stream above - doc.Load(ms)
this.ReportViewer1.ServerReport.LoadReportDefinition(stream);

Related

How to read a local json file and display

newbie here,I could not find any example on Xamarin Forms read a local json file and display it. I need to do a local testing to read the local Json file.
1) Where do I save the json file for reading? in Android and iOS Projects or just in PCL project?
2) How to read the file?
here the code but it is not complete as I dont how to read the file.
using (var reader = new System.IO.StreamReader(stream))
{
var json = reader.ReadToEnd();
var rootobject = JsonConvert.DeserializeObject<Rootobject>(json);
whateverArray = rootobject.Whatever;
}
The code miss the Path and others which required.
You can directly add your JSON file in PCL. Then change build action to Embedded Resource
Now you can read Json data by:
var assembly = typeof("<ContentPageName>").GetTypeInfo().Assembly;
Stream stream = assembly.GetManifestResourceStream("Your_File.json");
using (var reader = new System.IO.StreamReader(stream))
{
var json = reader.ReadToEnd();
var data= JsonConvert.DeserializeObject<Model>(json);
}

Decrypt PDF file on client side and view with pdf.js

I'm working on a project that all pdf files are encrypted on Web Server.
With XMLHttpRequest I get content of the encrypted pdf file. Then with JavaScript tools I decrypt the file. After all assign the content of file to a javascript variable as decrypted_file. All this is done at client side.
Here is what i want to do;
pdf.js renders and views pdf file that is located on web server or the same directory base.
How could I handle pdf.js to get content from javascript variable not url as "http//yourdomain.com/first-test.pdf or file as "first-test.pdf"?
Any answers are welcome, thank you.
Assuming that you are using the viewer.html of PDF.js, opening a PDF file from data is as easy as calling PDFViewerApplication.open with the right parameters.
Example: Typed arrays (Uint8Array / ArrayBuffer / ..)
// in viewer.html
var data = new Uint8Array( /* ... data ... */ );
PDFViewerApplication.open(data);
Example: Blob / File objects
// in viewer.html
var data = new Blob([ '%PDF....'] , {type: 'application/pdf'});
var url = URL.createObjectURL(data);
PDFViewerApplication.open(url);
Example: data URL (if supported by browser)
var url = 'data:application/pdf;base64,....';
PDFViewerApplication.open(url);
Example: data URL (any browser)
This consists of two steps: Decoding the base64 data-URL, and then converting the binary string to an Uint8Array.
var url = 'data:application/pdf;base64,....';
var data = url.split(';base64,')[1];
// Decode base64
var binaryString = atob(data);
// Convert binary string to Uint8Array
data = new Uint8Array(binaryString.length);
for (var i = 0, ii = binaryString.length; i < ii; ++i) {
data[i] = binaryString.charCodeAt(i);
}
PDFViewerApplication.open(data);
Example: Using PDF.js in a frame
<iframe src="viewer.html" id="pdfjsframe"></iframe>
<script>
var pdfjsframe = document.getElementById('pdfjsframe');
// At the very least, wait until the frame is ready, e.g via onload.
pdfjsframe.onload = function() {
var data = ... data here or elsewhere ... ;
pdfjsframe.contentWindow.PDFViewerApplication.open(data);
};
</script>

need to automate the RDLC reporting through SSIS script task?

Currently I'm calling RDLC report in asp.net application, where .rdlc is calling and we passing a data source and report in generated as PDF, the entire process initiate on a BUTTON click and report is generate.
Now this process need to automate and report should generate on Monday morning.
There is some suggestion come out that we can use SSIS Script Task and we can call external DLL and can call .rdlc file too to generate the report and then we can schedule SSIS package?
I never having experience on SSIS side, need your suggestion and how to do that, if there is possibilities? Thank You!
Use SSRS to schedule the report to run. No need for ASP.net or SSIS, SSRS has scheduling built in.
You can use SSRS subscription to send the report. If you really want the SSIS to send the report. you can do the following.
Create the report in SSRS
Deploy the report into report server
Create the SSIS package
Drag your Script task into the package.
You could use the following code snippet to send SSRS report using SSIS.
You should create some of the SSIS variables to store the report and render information.
RenderExtension ==> pdf
RenderFileName ==> Name of the file you want write
RenderFormat ==> PDF
RenderOutputPath==> Location to write the file
SSRSConnection ==>
http://localhost/ReportServer/reportexecution2005.asmx [Location of
your report services]
SSRSFolderName ==> Folder name of the report you deployed
SSRSReportName ==> Name of the report
In the following snippet.
public void Main()
{
var rExtension = Dts.Variables["RenderExtension"].Value.ToString();
var rFileName = Dts.Variables["RenderFileName"].Value.ToString();
var rFormat = Dts.Variables["RenderFormat"].Value.ToString();
var rOutputPath = Dts.Variables["RenderOutputPath"].Value.ToString();
var ssrsConnection = Dts.Variables["SSRSConnection"].Value.ToString();
var ssrsFolderName = Dts.Variables["SSRSFolderName"].Value.ToString();
var ssrsReportName = Dts.Variables["SSRSReportName"].Value.ToString();
ReportExecutionService rs=new ReportExecutionService();
Byte[] results;
string encoding = string.Empty;
string mimetype = string.Empty;
string extension = string.Empty;
Warning[] warnings = null;
string[] streamId = null;
string deviceInfo = null;
rs.Credentials = System.Net.CredentialCache.DefaultCredentials;
rs.Url = ssrsConnection;
try
{
var reportpath = string.Format("/{0}/{1}", ssrsFolderName, ssrsReportName);
rs.LoadReport(reportpath, null);
//Adding Parameters
//Commenting the following line Till we test the functionality
ParameterValue[] paramValues = new ParameterValue[4];
ParameterValue paramValue = new ParameterValue();
paramValue.Name = "ReportParamName";
paramValue.Value = "X,Y,Z";
paramValues[0] = paramValue;
rs.SetExecutionParameters(paramValues, "en-US");
results = rs.Render(rFormat, deviceInfo, out extension, out mimetype, out encoding, out warnings, out streamId);
var filewithdatetime = string.Format("{0}_{1}",rFileName,DateTime.Now.ToString("yyyy_MM_dd_hhmmss"));
string path = string.Format(#"{0}\{1}.{2}", rOutputPath, filewithdatetime, rExtension);
MessageBox.Show(path);
using (FileStream stream = File.OpenWrite(path))
{
stream.Write(results, 0, results.Length);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.StackTrace);
}
Dts.TaskResult = (int)ScriptResults.Success;
}

Target Object Tag with PDF stream in HTML page

I am using crystal reports in a .NET 2.0 asp.net website to create a PDF from the report. I then want to stream the report to the browser, which I already know how to do. What I don't know how to do is target the object tag the will hold the PDF. Does someone know how to do this within HTML with javascript or any other way?
Thanks in advance for any help that can be given.
I wanted to come back and answer this after finding out what I had to do. I had to create a separate aspx page and called it PDFView.aspx. I then added the code to the PageLoad event:
if (!IsPostBack)
{
ReportDocument rpt;
rpt = (ReportDocument)Session["CrystalReport"];
System.IO.Stream myStream;
CrystalDecisions.Shared.ExportOptions myExportOptions;
myExportOptions = myReport.ExportOptions;
myExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat;
myExportOptions.FormatOptions = new CrystalDecisions.Shared.PdfRtfWordFormatOptions();
CrystalDecisions.Shared.ExportRequestContext myExportRequestContext = new CrystalDecisions.Shared.ExportRequestContext();
myExportRequestContext.ExportInfo = myExportOptions;
//SetReportParameter("pPrinterFriendly", true, (ReportClass)myReport);
System.Web.HttpContext.Current.Response.ClearContent();
System.Web.HttpContext.Current.Response.ClearHeaders();
System.Web.HttpContext.Current.Response.ContentType = "application/pdf";
myStream = myReport.FormatEngine.ExportToStream(myExportRequestContext);
Byte[] myBuffer = new Byte[myStream.Length];
myStream.Read(myBuffer, 0, (int)myStream.Length);
System.Web.HttpContext.Current.Response.BinaryWrite(myBuffer);
System.Web.HttpContext.Current.Response.Flush();
}
I created the report object setting all parameters and datasource in the calling aspx page and the wrote the report to a session variable for retrieval when the PDFView.aspx page is loaded. I then used the code above to retrieve, execute and stream the report as a binary stream "the binary PDF" to the browsers response stream.
The PDFView.aspx page is referenced in the calling page with an object tag like this:
<object id="pdfObj" type="application/pdf" style="width:60%;height:95%;position:relative;top:2%;left:0%;right:10%;bottom:10%;margin:0px;padding:0px;border:0px;" data="PDFView.aspx"></object>

Is it possible to load a local file without having to ask the user to browse to it first in an AIR Application?

I'm writing a small application for myself and instead of using a database I'd like to just use Excel to store the small amount of data I have on my local file system. I want to be able to load that data without having to use the typical FileReference browse() method as it would just be annoying to do every time I use the application.
The code below seems to find the file fine as the file.exists method below and most of the other attributes seem to be correct but the file.data is always null.
I'm guessing this is a security issue and that's why I'm running into this problem but I thought I'd ask and see if there is in fact a way around this problem.
var file:File = new File(fullPath + "\\" + currentFolder + ".txt");
if(file.exists) {
var byteArray:ByteArray = file.data;
}
If you want to read the content of a file, use the following code:
var stream:FileStream = new FileStream();
stream.open("some path here", FileMode.READ);
var fileData:String = stream.readUTFBytes(stream.bytesAvailable);
trace(fileData);
The data property is inherited from FileReference class and it will be populated only after a load call (see this link).
You're close, you just need to combine that with a FileStream object
var fileStream:FileStream = new FileStream();
fileStream.open(file, FileMode.READ);
var str:String = fileStream.readMultiByte(file.size, File.systemCharset);
trace(str);
more info here

Resources