Skip to main content

Exporting Report without reportviewer

private void MyReport()
{
DateTime date = DateTime.Now.AddMonths(-1);
string FileName = "MyReport_" + date.ToString("MMyyyy") + ".xls";
string path = @"d:\MyReportFolder\MyReport\";
DataSet ds = new DataSet();
DataTable dt = new DataTable();
SqlConnection Sqlconnection = null;
SqlCommand cmdgetStatusreport;
if (!Directory.Exists(path + FileName))
{
try
{
Sqlconnection = new SqlConnection(ConnectionString);
Sqlconnection.Open();
cmdgetStatusreport = new SqlCommand("MyReport_sp",
Sqlconnection);
cmdgetStatusreport.CommandType = CommandType.StoredProcedure;
cmdgetStatusreport.CommandTimeout = 0;
SqlDataAdapter daStatusreport = new
SqlDataAdapter(cmdgetStatusreport);
SqlDataAdapter daStatusreport1 = new
SqlDataAdapter(cmdgetStatusreport);
daStatusreport.Fill(ds);
daStatusreport1.Fill(dt);
Sqlconnection.Close();
}
catch (Exception ex)
{
WriteFileMappingLog("Status ReportViewer: " +
ex.Message.ToString());
}
Microsoft.Reporting.WinForms.ReportViewer ReportViewer1 = new
ReportViewer();
ReportViewer1.Reset();
ReportViewer1.LocalReport.Dispose();
ReportViewer1.LocalReport.DataSources.Clear();
string rdlcpath = AppDomain.CurrentDomain.BaseDirectory.ToString()
+ @"\Report1.rdlc"; ;
ReportViewer1.ProcessingMode = ProcessingMode.Local;
ReportViewer1.LocalReport.ReportPath = rdlcpath;
//
"D:\\Sunil\\newDevelopement\\MyReport\\Report1.rdlc";
ReportViewer1.LocalReport.DataSources.Add(new
ReportDataSource("VMCMembershipDataSet_VMCAccount_StatusReport".ToString().Trim(),
ds.Tables[0]));
try
{
Warning[] warnings;
string[] streamids;
string mimeType;
string encoding;
string extension;
string deviceInfo = null;
byte[] bytes = ReportViewer1.LocalReport.Render(
"Excel", deviceInfo, out mimeType, out encoding,
out extension,
out streamids, out warnings);
// writing bytes to file
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
FileStream fs = new FileStream(path + FileName,
FileMode.Create,FileAccess.ReadWrite);
fs.Write(bytes, 0, bytes.Length);
fs.Close();
}
catch (Exception ex)
{
WriteFileMappingLog("Status ReportViewer: render " +
ex.Message.ToString());
}
}
}

Popular posts from this blog

How to export data grid in to Excel file using c#

How To increase Wi-Fi speed on Android phone

How To Increase Wi-Fi speed on Android phone You can restart Wi-Fi modem and again connect to Wi-Fi network to get maximized internet speed.Be aware of people around you who can utilize Wi-Fi connection to browse on their own systems. Always apply password protection avoid unauthorized usage of data.Update your Android phone’s browser and OS to the latest definitions.If you are using 2.4 Ghz cordless Android phone, make sure there should no confliction between 2.4 Ghz Wireless router, as it may cause slow internet speed on your phone.You can check manufacturer’s website for newly updated firmware downloads to upgrade router.Check for background running applications that are using internet connection and close all of them which you do not need while browsing.See if you are using connection with DNS settings. If no, you can change DNS settings on your Android device.Also keep clearing browsing history, cache, cookies and other browser junk to experience fast browsing.Switch to other brow…