Ever needed to convert an oracle report to pdf/excel/word? Here is a solution
Using the code
Just simple Code which runs the oracle report and convert that in to a blob and then opens it using desired format
Blocks of code should be set as style "Formatted" like this:
Collapse
using System.Net;
using System.IO;
public void RunReport(string ReportFormat)
{
byte[] blb = RunReport();
HttpResponse hr = this.Response;
hr.AddHeader("Content-Disposition", "attachment;");
hr.BinaryWrite(blb);
if (ReportFormat == "PDF")
{
hr.ContentType = "application/pdf";
}
else if (ReportFormat == "EXCEL")
{
hr.ContentType = "application/vnd.ms-excel;charset=ISO-8859-1";
}
else
{
hr.ContentType = "application/msword";
}
hr.Flush();
}
public byte[] RunReport()
{
WebRequest request = null;
HttpWebResponse response = null;
Stream dataStream = null;
string reportURL =
@"https://Server/reports/rwservlet?cmdkey=PROD&destype=cache&desformat=DesiredFormat&report=ReportName.rdf&Param1=ABC&PARAM2=123";
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(reportURL);
myRequest.Accept = @"application/vnd.ms-excel";
dataStream = myRequest.GetResponse().GetResponseStream();
MemoryStream memStream = new MemoryStream();
BinaryWriter writer = null;
BinaryReader reader = null;
byte[] buffer;
try
{
writer = new BinaryWriter(memStream);
reader = new BinaryReader(dataStream);
buffer = new byte[250];
buffer = reader.ReadBytes(250);
while (buffer.Length > 0)
{
writer.Write(buffer);
buffer = reader.ReadBytes(250);
}
}
catch (Exception ex)
{
}
finally
{
if (writer != null)
writer.Close();
if (reader != null)
reader.Close();
memStream.Close();
}
byte[] blb = memStream.ToArray();
return blb;
}