Resource Responses

Search Guest Response by Email:
Total 90 responses found.
Validate ZIP Code
try like this also
private void btnValidate_Click(object sender, System.EventArgs e)
{
bool IsValid = true;
if (!Regex.IsMatch(txtZip.Text, @"^\s*(\d{5}|(\d{5}-\d{4}))\s*$"))
{
txtZip.ForeColor = Color.Red;
IsValid = false;
}
else
{
txtZip.ForeColor = Color.Black;
}
}

more reference about this

http://www.dotnetspider.com/resources/22701-Validate-Zip-Code.aspx
Author: Ultimaterengan      Posted Date: 10 Feb 2014
Method to reverse the string
In this article I'm going to explain how to reverse a string using asp.net.
Here we have a two text box and one button control.
we have to reverse the string inside the text box and print that out on another text box by clicking Reverse button.


using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page
{
#region "Reverse Click Event"
protected void btnReverse_Click(object sender, EventArgs e)
{
TextBox2.Text = ToReverseString(TextBox1.Text.ToString());
}
#endregion
#region "ReverseString"
public string ToReverseString(string strInputString)
{
//take one new string
string strFinalString = string.Empty;
for (int count = strInputString.Length - 1; count >= 0; count--)
{
//store the reverse character in seperate string
strFinalString = strFinalString + strInputString[count];
}
return strFinalString;
}
#endregion
}
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>





Untitled Page


















Enter the String



Reverse String








Author: Ultimaterengan      Posted Date: 10 Feb 2014
what is the difference between Convert.toString and .toString ()
In this article I'm going to explain what is the Difference between convert.ToString() and object.ToString()? ToString is the major formatting method in .net framework. Convert.Tostring method is used to convert the spefied value to its equivalent string representaion. Object.Tostring method return string that represent the current object.


ToString is the major formatting method in .net framework.
Convert.Tostring method is used to convert the spefied value to its equivalent string representaion. Object.Tostring method return string that represent the current object. The basic difference between them is "Convert.ToString(variableName)" handles NULL values even if variable value become null but "variable.ToString()" will not handle NULL values it will throw a NULL reference exception error.

Example:-

---The following statement Returns a null reference exception for strname variable.
string strname;
object ivariable = null;
strname = ivariable.ToString();

---The following eturns an empty string for strname and does not throw an exception. If you dont
string strname;
object ivariable = null;
strname = Convert.ToString(ivariable);
Author: Ultimaterengan      Posted Date: 09 Feb 2014
Sending Email Through ASP.NET using C#
Try like this also

First we need to import System.Web.Mail namespace. The system.Web.Mail namespace contains classes that enable you to construct and send messages using the CDOSYS message component.

To Add this reference follow below steps

1)On the project menu click add reference

2)After That click .net Tab, locate System.Web.ddl, and then click Select.
3)Click ok in the add references.


Design Page

















Coding Page



using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net.Mail;
using System.Net;

public partial class _Default : System.Web.UI.Page
{
protected void btnSend_Click(object sender, EventArgs e)
{
try
{
MailMessage msg = new MailMessage(txtFromMailID.Text.ToString().Trim(), txtTomailid.Text.ToString().Trim(), txtsubject.Text.ToString(), txtbody.Text.ToString());
MailAddress SendCC = new MailAddress(txtCC.Text.ToString());
msg.CC.Add(SendCC);
SmtpClient mailClient = new SmtpClient(txtsmtpaddress.Text.ToString().Trim(), Convert.ToInt32(txtPortAddress.Text.ToString().Trim()));
NetworkCredential NetCrd = new NetworkCredential(txtFromMailID.Text.ToString(), txtPassword.Text.ToString());
mailClient.UseDefaultCredentials = false;
mailClient.Credentials = NetCrd;
if (Convert.ToInt32(txtPortAddress.Text.ToString().Trim()) == 587)
{
mailClient.EnableSsl = true;
}
else
{
mailClient.EnableSsl = false;
}
mailClient.DeliveryMethod = SmtpDeliveryMethod.Network;

mailClient.Send(msg);
Page.ClientScript.RegisterStartupScript(this.GetType(), "alertScript", "Mail Sent", true);
}
catch (Exception ex)
{ Page.ClientScript.RegisterStartupScript(this.GetType(), "alertScript", ex.Message, true);
}
}
}
Author: Ultimaterengan      Posted Date: 09 Feb 2014
How to Create Setup file for .NET Windows application?
Try this article also

Create Setup Project:-
Step1:
File->New->Project->Choose Setup and deloyment from other Project Types in Project Types.
Then go to templates click Setup wizard.Then give new name to Setup Wizard and choose your path.For Example Setup1
Then click Ok.(See Image:1)
Step2:-
Welcome to the Setup wizard(1-4) window will dispaly(See Image:2).Then click Next.
Step3:-
Setup wizard(2-4) window will dispaly.(See Image:3)
Do you want to create a setup program to insatll an application? message will appear.
Default is "Create a setup for a windows application".
No need to change anything.Just click next button.
Step 4:-
Setup wizard(3-4) window will dispaly.(See Image:4)
Choose Files to include message will appear with in window.
Which additional files do you want to include?
Click the add button.After click the add button "Add Files" window will appear(See Image:6) then go the project location(For Ex:-Windows application1)
Click The project(Windows application1)->click Windows application1->choose bin folder->Debug->Finally choose "WindowsApplication1.vshost.exe"
Then click the open button.
You will get the your exe path with in Setup wizard(3-4) window.Then Click The Next Button.

Step 5:-
Setup wizard(4-4) window will dispaly.(See Image:5)
The project summary will display based on your choose.
Project type: Create a setup for a Windows application
Project groups to include: (none)
Additional files:
C:\Documents and Settings\ramku.g\Desktop\WindowsApplication1\WindowsApplication1\bin\Debug\WindowsApplication1.vshost.exe
Project Directory: C:\Documents and Settings\ramku.g\Desktop\Setup1\Setup1\Setup1.vdproj
Project Directory: Your path will display
Then click finish button.

Step 6:-
File System(Setup) window will dispaly.(See Image:7)
Then go to the solution explorer window(See Image:8) and Right click the project name then build the windows application.
Build Success message will dispaly on status bar.After that right click the project name then click install.
Step 7:-
Welcome to the setup wizard window will dispaly(See Image:9).Then click next Button
"Choose the installation folder" window will dispaly(See Image:10).Selet the Insatllation folder path by clicking browse button.
choose justme or Every one from radiobutton.
Then click next button.
Step 8:-
Confirm installation window will dispaly(See Image:11).
If you want to install ,just click Next.
Setup will install(See Image:12).
Step 9:-
After install installaion complete window will display(See Image:13).
Then close.Just go that path and choose that exe and run it.


http://www.dotnetspider.com/resources/39105-How-create-Setup-for-windows-application.aspx
Author: Ultimaterengan      Posted Date: 07 Feb 2014
Send E-mail with Dynamic Body
In this article I''m going to explain how to Export Crystal Report to PDF and send in Email as Attachment using Windows Service.Windows services are applications that will run in the background and then perform various task. This application does not have user interface. Windows Service are controlled by using service control manager. If you want to start and stop the service then go to Control Panel ---> Administrative Tools ---> Services. Right click the service and then select Start or stop.







In this article I''m going to explain how to Export Crystal Report to PDF and send in Email as Attachment using Windows Service.Windows services are applications that will run in the background and then perform various task.
This application does not have user interface. Windows Service are controlled by using service control manager. If you want to start and stop the service then go to Control Panel ---> Administrative Tools ---> Services. Right click the service and then select Start or stop..


Step 1:
Select File-->New -->click Project and then project window will display.


Step 2:
Expand "Visual C#" tab and select Windows Service and then give proper name for your service.

Step 3:
Expand "Visual C#" tab and select Windows Service and then give proper name for your service.

Step 4:
Right click on the form and then click Add Installer and then project Installer added to your project.


Step 5:
Select ServiceInstaller1 go to properties and then set DisplayName, ServiceName and finally set StartType equal to Automatic or manual.
step 6:

select ServiceProcessInstaller1 and set Account property as LocalSystem.
Step 7:
Add ScheduledService form Within this form we need to add two crystalreport file.

Step 8:
Build the application and then get exe of this application from bin directory.

By using following steps you can install and uninstall the windows service easily. By using InstallUtil.exe we can install or uninstall
windows service easily.

1)On the Windows Start menu, choose Visual Studio (2008,2010,2003, 2005) , Visual Studio Tools, Visual Studio Command Prompt.

2)Access the directory in which your project's compiled executable file is located.

3)Run InstallUtil.exe from the command prompt with your project's output as a parameter. For example
installutil WindowsService1.exe

4)To uninstall the Windows Service use below statement
installutil /u WindowsService1.exe

Herewith I have given full code kindly check it. Create two Crystal reports and one notepad file in D & C directory and then try this example.



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
using System.Text;
using System.Timers;
using System.IO;
using System.Data.SqlClient;
using System.Net.Mail;
using CrystalDecisions.Shared;
using CrystalDecisions.CrystalReports.Engine;

namespace WindowsService1
{

public partial class ScheduledService : ServiceBase
{
Boolean bolfa = false;
Boolean bolfa22 = false;
Boolean bolfa2 = false;
DateTime timeOnInit = DateTime.Now;
DataSet ds = new DataSet();
Timer timer = new Timer();
public ScheduledService()
{
InitializeComponent();
}
//This method is used to raise event during start of service
protected override void OnStart(string[] args)
{
//add this line to text file during start of service
TraceService("start service");
myservice();
//handle Elapsed event
timer.Elapsed += new ElapsedEventHandler(OnElapsedTime);

//This statement is used to set interval to 1 minute (= 60,000 milliseconds)
//36000000 36000000
timer.Interval = 36000000;
//timer.Interval = 60000;

//enabling the timer
timer.Enabled = true;
}
//This method is used to stop the service
protected override void OnStop()
{
timer.Enabled = false;
TraceService("stopping service");
}
private void OnElapsedTime(object source, ElapsedEventArgs e)
{
TraceService("Another entry at " + DateTime.Now);
myservice();
}
private DataTable BindReports()
{
try
{
string conString = @"Data Source=192.168.1.168;Initial Catalog=databasename;Persist Security Info=True;User ID=userid;Password=password";
DataTable dtReport = new DataTable();
SqlConnection con = new SqlConnection(conString);
SqlCommand cmdSetupGetdata = new SqlCommand("[Attendance_NoEntryStoredprocedure]", con);
cmdSetupGetdata.CommandType = CommandType.StoredProcedure;
cmdSetupGetdata.CommandTimeout = 600;
cmdSetupGetdata.Parameters.AddWithValue("@BR", "ALL");
SqlDataAdapter mySqlDataAdapter1 = new SqlDataAdapter();
mySqlDataAdapter1.SelectCommand = cmdSetupGetdata;
con.Open();
mySqlDataAdapter1.Fill(dtReport);
con.Close();
return dtReport;
}
catch (Exception ex)
{
throw ex;
}

}
private DataTable BindReports2()
{
try
{

string conString = @"Data Source=192.168.1.168;Initial Catalog=databasename;Persist Security Info=True;User ID=userid;Password=password";
DataTable dtReport = new DataTable();
SqlConnection con = new SqlConnection(conString);
SqlCommand cmdSetupGetdata = new SqlCommand("ReimburmentReportStoredprocedure", con);
cmdSetupGetdata.CommandType = CommandType.StoredProcedure;
cmdSetupGetdata.CommandTimeout = 600;
SqlDataAdapter mySqlDataAdapter1 = new SqlDataAdapter();
mySqlDataAdapter1.SelectCommand = cmdSetupGetdata;
con.Open();
mySqlDataAdapter1.Fill(dtReport);
con.Close();




return dtReport;
}
catch (Exception ex)
{
throw ex;
}
}
private void myservice()
{


bolfa2 = true;
ReportDocument cryRpt;

cryRpt = new ReportDocument();
cryRpt.Load(@"D:\DailyAbsentListReportfile.rpt");

ParameterFieldDefinitions crParameterFieldDefinitions;
ParameterFieldDefinition crParameterFieldDefinition;
ParameterValues crParameterValues = new ParameterValues();
ParameterDiscreteValue crParameterDiscreteValue = new ParameterDiscreteValue();

crParameterDiscreteValue.Value = "ALL";
crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields;
crParameterFieldDefinition = crParameterFieldDefinitions["Branch"];
crParameterValues = crParameterFieldDefinition.CurrentValues;

crParameterValues.Clear();
crParameterValues.Add(crParameterDiscreteValue);
crParameterFieldDefinition.ApplyCurrentValues(crParameterValues);




crystalReportViewer1.ReportSource = cryRpt;
crystalReportViewer1.Refresh();
DataTable dtReports = BindReports();
cryRpt.SetDataSource(dtReports);
crystalReportViewer1.ReportSource = dtReports;
crystalReportViewer1.Refresh();
ExportOptions rptExportOption;
DiskFileDestinationOptions rptFileDestOption = new DiskFileDestinationOptions();
PdfRtfWordFormatOptions rptFormatOption = new PdfRtfWordFormatOptions();

string reportFileName = @"D:\DailyAbsentListPDFFile.pdf";

rptFileDestOption.DiskFileName = reportFileName;
rptExportOption = cryRpt.ExportOptions;
{
rptExportOption.ExportDestinationType = ExportDestinationType.DiskFile;
//if we want to generate the report as PDF, change the ExportFormatType as "ExportFormatType.PortableDocFormat"
//if we want to generate the report as Excel, change the ExportFormatType as "ExportFormatType.Excel"
rptExportOption.ExportFormatType = ExportFormatType.PortableDocFormat;
rptExportOption.ExportDestinationOptions = rptFileDestOption;
rptExportOption.ExportFormatOptions = rptFormatOption;
}


try
{
cryRpt.Export();
}
catch (Exception ex)
{


}

ReportDocument cryRptReimburement;

cryRptReimburement = new ReportDocument();
cryRptReimburement.Load(@"D:\DailyReimbursementDetailsReportFile.rpt");





crystalReportViewer2.ReportSource = cryRptReimburement;
crystalReportViewer2.Refresh();
DataTable dtReportsReimburement = BindReports2();
cryRptReimburement.SetDataSource(dtReportsReimburement);
crystalReportViewer2.ReportSource = dtReportsReimburement;
crystalReportViewer2.Refresh();
ExportOptions rptExportOption2;
DiskFileDestinationOptions rptFileDestOption2 = new DiskFileDestinationOptions();
PdfRtfWordFormatOptions rptFormatOption2 = new PdfRtfWordFormatOptions();

string reportFileName2 = @"D:\Reimburment.pdf";

rptFileDestOption2.DiskFileName = reportFileName2;
rptExportOption2 = cryRptReimburement.ExportOptions;
{
rptExportOption2.ExportDestinationType = ExportDestinationType.DiskFile;
//if we want to generate the report as PDF, change the ExportFormatType as "ExportFormatType.PortableDocFormat"
//if we want to generate the report as Excel, change the ExportFormatType as "ExportFormatType.Excel"
rptExportOption2.ExportFormatType = ExportFormatType.PortableDocFormat;
rptExportOption2.ExportDestinationOptions = rptFileDestOption2;
rptExportOption2.ExportFormatOptions = rptFormatOption2;
}
try
{
cryRptReimburement.Export();
}
catch (Exception ex)
{


}



SmtpClient client = new SmtpClient(); // setting email smtp client to send email from
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.EnableSsl = false;
client.Host = "smtp.gmail.com"; //google mail smtp host
client.Port = 587; //Google mail port
System.Net.NetworkCredential credentials = new System.Net.NetworkCredential("fromMailid@gmail.com", "password"); //your email and password
client.UseDefaultCredentials = false;
client.Credentials = credentials;
//foreach (DataRow dr in ds.Tables[0].Rows)
//{
MailMessage mm3 = new MailMessage("frommailid@.com", "renganathan@gmail.com"); //fields in the database

// Add attachment
string attachmentPath = @"D:\DailyAbsentList.pdf";
mm3.Attachments.Add(new Attachment(attachmentPath));
string attachmentPath2 = @"D:\Reimburment.pdf";
mm3.Attachments.Add(new Attachment(attachmentPath2));

mm3.Subject = "Sending Auto Mail From windows Service"; //Email Subject to send out
mm3.Body = "Herewith I have attached PDF file " + Environment.NewLine + "Regards" + Environment.NewLine + "Rengan";
mm3.IsBodyHtml = true;
client.Send(mm3);
mm3.Dispose();




}

private void TraceService(string content)
{

//set up a filestream
FileStream fs = new FileStream(@"C:\test.txt", FileMode.OpenOrCreate, FileAccess.Write);

//set up a streamwriter for adding text
StreamWriter sw = new StreamWriter(fs);

//find the end of the underlying filestream
sw.BaseStream.Seek(0, SeekOrigin.End);

//add the text
sw.WriteLine(content);
//add the text to the underlying filestream

sw.Flush();
//close the writer
sw.Close();


}
}
}

check my resource

http://www.dotnetspider.com/resources/45524-Export-Crystal-Report-to-PDF-and-send-in-Email-as-Attachment-using-Windows.aspx

Author: Ultimaterengan      Posted Date: 06 Feb 2014
How to send mail or messages on specific time or Schedule time
In this article I''m going to explain how to Export Crystal Report to PDF and send in Email as Attachment using Windows Service.Windows services are applications that will run in the background and then perform various task. This application does not have user interface. Windows Service are controlled by using service control manager. If you want to start and stop the service then go to Control Panel ---> Administrative Tools ---> Services. Right click the service and then select Start or stop.







In this article I''m going to explain how to Export Crystal Report to PDF and send in Email as Attachment using Windows Service.Windows services are applications that will run in the background and then perform various task.
This application does not have user interface. Windows Service are controlled by using service control manager. If you want to start and stop the service then go to Control Panel ---> Administrative Tools ---> Services. Right click the service and then select Start or stop..


Step 1:
Select File-->New -->click Project and then project window will display.


Step 2:
Expand "Visual C#" tab and select Windows Service and then give proper name for your service.

Step 3:
Expand "Visual C#" tab and select Windows Service and then give proper name for your service.

Step 4:
Right click on the form and then click Add Installer and then project Installer added to your project.


Step 5:
Select ServiceInstaller1 go to properties and then set DisplayName, ServiceName and finally set StartType equal to Automatic or manual.
step 6:

select ServiceProcessInstaller1 and set Account property as LocalSystem.
Step 7:
Add ScheduledService form Within this form we need to add two crystalreport file.

Step 8:
Build the application and then get exe of this application from bin directory.

By using following steps you can install and uninstall the windows service easily. By using InstallUtil.exe we can install or uninstall
windows service easily.

1)On the Windows Start menu, choose Visual Studio (2008,2010,2003, 2005) , Visual Studio Tools, Visual Studio Command Prompt.

2)Access the directory in which your project's compiled executable file is located.

3)Run InstallUtil.exe from the command prompt with your project's output as a parameter. For example
installutil WindowsService1.exe

4)To uninstall the Windows Service use below statement
installutil /u WindowsService1.exe

Herewith I have given full code kindly check it. Create two Crystal reports and one notepad file in D & C directory and then try this example.



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
using System.Text;
using System.Timers;
using System.IO;
using System.Data.SqlClient;
using System.Net.Mail;
using CrystalDecisions.Shared;
using CrystalDecisions.CrystalReports.Engine;

namespace WindowsService1
{

public partial class ScheduledService : ServiceBase
{
Boolean bolfa = false;
Boolean bolfa22 = false;
Boolean bolfa2 = false;
DateTime timeOnInit = DateTime.Now;
DataSet ds = new DataSet();
Timer timer = new Timer();
public ScheduledService()
{
InitializeComponent();
}
//This method is used to raise event during start of service
protected override void OnStart(string[] args)
{
//add this line to text file during start of service
TraceService("start service");
myservice();
//handle Elapsed event
timer.Elapsed += new ElapsedEventHandler(OnElapsedTime);

//This statement is used to set interval to 1 minute (= 60,000 milliseconds)
//36000000 36000000
timer.Interval = 36000000;
//timer.Interval = 60000;

//enabling the timer
timer.Enabled = true;
}
//This method is used to stop the service
protected override void OnStop()
{
timer.Enabled = false;
TraceService("stopping service");
}
private void OnElapsedTime(object source, ElapsedEventArgs e)
{
TraceService("Another entry at " + DateTime.Now);
myservice();
}
private DataTable BindReports()
{
try
{
string conString = @"Data Source=192.168.1.168;Initial Catalog=databasename;Persist Security Info=True;User ID=userid;Password=password";
DataTable dtReport = new DataTable();
SqlConnection con = new SqlConnection(conString);
SqlCommand cmdSetupGetdata = new SqlCommand("[Attendance_NoEntryStoredprocedure]", con);
cmdSetupGetdata.CommandType = CommandType.StoredProcedure;
cmdSetupGetdata.CommandTimeout = 600;
cmdSetupGetdata.Parameters.AddWithValue("@BR", "ALL");
SqlDataAdapter mySqlDataAdapter1 = new SqlDataAdapter();
mySqlDataAdapter1.SelectCommand = cmdSetupGetdata;
con.Open();
mySqlDataAdapter1.Fill(dtReport);
con.Close();
return dtReport;
}
catch (Exception ex)
{
throw ex;
}

}
private DataTable BindReports2()
{
try
{

string conString = @"Data Source=192.168.1.168;Initial Catalog=databasename;Persist Security Info=True;User ID=userid;Password=password";
DataTable dtReport = new DataTable();
SqlConnection con = new SqlConnection(conString);
SqlCommand cmdSetupGetdata = new SqlCommand("ReimburmentReportStoredprocedure", con);
cmdSetupGetdata.CommandType = CommandType.StoredProcedure;
cmdSetupGetdata.CommandTimeout = 600;
SqlDataAdapter mySqlDataAdapter1 = new SqlDataAdapter();
mySqlDataAdapter1.SelectCommand = cmdSetupGetdata;
con.Open();
mySqlDataAdapter1.Fill(dtReport);
con.Close();




return dtReport;
}
catch (Exception ex)
{
throw ex;
}
}
private void myservice()
{


bolfa2 = true;
ReportDocument cryRpt;

cryRpt = new ReportDocument();
cryRpt.Load(@"D:\DailyAbsentListReportfile.rpt");

ParameterFieldDefinitions crParameterFieldDefinitions;
ParameterFieldDefinition crParameterFieldDefinition;
ParameterValues crParameterValues = new ParameterValues();
ParameterDiscreteValue crParameterDiscreteValue = new ParameterDiscreteValue();

crParameterDiscreteValue.Value = "ALL";
crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields;
crParameterFieldDefinition = crParameterFieldDefinitions["Branch"];
crParameterValues = crParameterFieldDefinition.CurrentValues;

crParameterValues.Clear();
crParameterValues.Add(crParameterDiscreteValue);
crParameterFieldDefinition.ApplyCurrentValues(crParameterValues);




crystalReportViewer1.ReportSource = cryRpt;
crystalReportViewer1.Refresh();
DataTable dtReports = BindReports();
cryRpt.SetDataSource(dtReports);
crystalReportViewer1.ReportSource = dtReports;
crystalReportViewer1.Refresh();
ExportOptions rptExportOption;
DiskFileDestinationOptions rptFileDestOption = new DiskFileDestinationOptions();
PdfRtfWordFormatOptions rptFormatOption = new PdfRtfWordFormatOptions();

string reportFileName = @"D:\DailyAbsentListPDFFile.pdf";

rptFileDestOption.DiskFileName = reportFileName;
rptExportOption = cryRpt.ExportOptions;
{
rptExportOption.ExportDestinationType = ExportDestinationType.DiskFile;
//if we want to generate the report as PDF, change the ExportFormatType as "ExportFormatType.PortableDocFormat"
//if we want to generate the report as Excel, change the ExportFormatType as "ExportFormatType.Excel"
rptExportOption.ExportFormatType = ExportFormatType.PortableDocFormat;
rptExportOption.ExportDestinationOptions = rptFileDestOption;
rptExportOption.ExportFormatOptions = rptFormatOption;
}


try
{
cryRpt.Export();
}
catch (Exception ex)
{


}

ReportDocument cryRptReimburement;

cryRptReimburement = new ReportDocument();
cryRptReimburement.Load(@"D:\DailyReimbursementDetailsReportFile.rpt");





crystalReportViewer2.ReportSource = cryRptReimburement;
crystalReportViewer2.Refresh();
DataTable dtReportsReimburement = BindReports2();
cryRptReimburement.SetDataSource(dtReportsReimburement);
crystalReportViewer2.ReportSource = dtReportsReimburement;
crystalReportViewer2.Refresh();
ExportOptions rptExportOption2;
DiskFileDestinationOptions rptFileDestOption2 = new DiskFileDestinationOptions();
PdfRtfWordFormatOptions rptFormatOption2 = new PdfRtfWordFormatOptions();

string reportFileName2 = @"D:\Reimburment.pdf";

rptFileDestOption2.DiskFileName = reportFileName2;
rptExportOption2 = cryRptReimburement.ExportOptions;
{
rptExportOption2.ExportDestinationType = ExportDestinationType.DiskFile;
//if we want to generate the report as PDF, change the ExportFormatType as "ExportFormatType.PortableDocFormat"
//if we want to generate the report as Excel, change the ExportFormatType as "ExportFormatType.Excel"
rptExportOption2.ExportFormatType = ExportFormatType.PortableDocFormat;
rptExportOption2.ExportDestinationOptions = rptFileDestOption2;
rptExportOption2.ExportFormatOptions = rptFormatOption2;
}
try
{
cryRptReimburement.Export();
}
catch (Exception ex)
{


}



SmtpClient client = new SmtpClient(); // setting email smtp client to send email from
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.EnableSsl = false;
client.Host = "smtp.gmail.com"; //google mail smtp host
client.Port = 587; //Google mail port
System.Net.NetworkCredential credentials = new System.Net.NetworkCredential("fromMailid@gmail.com", "password"); //your email and password
client.UseDefaultCredentials = false;
client.Credentials = credentials;
//foreach (DataRow dr in ds.Tables[0].Rows)
//{
MailMessage mm3 = new MailMessage("frommailid@.com", "renganathan@gmail.com"); //fields in the database

// Add attachment
string attachmentPath = @"D:\DailyAbsentList.pdf";
mm3.Attachments.Add(new Attachment(attachmentPath));
string attachmentPath2 = @"D:\Reimburment.pdf";
mm3.Attachments.Add(new Attachment(attachmentPath2));

mm3.Subject = "Sending Auto Mail From windows Service"; //Email Subject to send out
mm3.Body = "Herewith I have attached PDF file " + Environment.NewLine + "Regards" + Environment.NewLine + "Rengan";
mm3.IsBodyHtml = true;
client.Send(mm3);
mm3.Dispose();




}

private void TraceService(string content)
{

//set up a filestream
FileStream fs = new FileStream(@"C:\test.txt", FileMode.OpenOrCreate, FileAccess.Write);

//set up a streamwriter for adding text
StreamWriter sw = new StreamWriter(fs);

//find the end of the underlying filestream
sw.BaseStream.Seek(0, SeekOrigin.End);

//add the text
sw.WriteLine(content);
//add the text to the underlying filestream

sw.Flush();
//close the writer
sw.Close();


}
}
}

check my resource

http://www.dotnetspider.com/resources/45524-Export-Crystal-Report-to-PDF-and-send-in-Email-as-Attachment-using-Windows.aspx

Author: Ultimaterengan      Posted Date: 06 Feb 2014
Export GridView to Excel using C#.Net
try like this also

How to export datagridview to excel format using c#?In this article I'm going to explain how to convert datagridview to excel format using c#. This is a requirement often in many projects as users may
want to save some data generated in applications for future reference.
Just drag and drop one datagridview and button control to your window application.


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.Office.Interop.Excel;

namespace WindowsApplication1
{
public partial class Form1 : Form
{
System.Data.DataTable dtblSkill = new System.Data.DataTable();
public Form1()
{
InitializeComponent();
dtblSkill.Columns.Add("SkillCode", typeof(string));
dtblSkill.Columns.Add("SkillName", typeof(string));
AddGridViewSkillColumns();
}
private void AddGridViewSkillColumns()
{
try
{

DataGridViewTextBoxColumn dgvtxtSkillCode = new DataGridViewTextBoxColumn();
dgvtxtSkillCode.Name = "SkillCode";
dgvtxtSkillCode.DataPropertyName = "SkillCode";
dgvtxtSkillCode.HeaderText = "Skill Code";
dgvtxtSkillCode.Width = 120;


DataGridViewTextBoxColumn dgvtxtSkillName = new DataGridViewTextBoxColumn();
dgvtxtSkillName.Name = "SkillName";
dgvtxtSkillName.HeaderText = "Skill Name";
dgvtxtSkillName.DataPropertyName = "SkillName";
dgvtxtSkillName.Visible = true;
dgvtxtSkillName.Width = 160;


dataGridView1.Columns.Add(dgvtxtSkillCode);
dataGridView1.Columns.Add(dgvtxtSkillName);

dataGridView1.DataSource = dtblSkill;
}
catch (Exception ex)
{
MessageBox.Show("Error Details" + ex.Message);
}
}

private void button1_Click(object sender, EventArgs e)
{
Microsoft.Office.Interop.Excel.Application wapp;
Microsoft.Office.Interop.Excel.Worksheet wsheet;
Microsoft.Office.Interop.Excel.Workbook wbook;
wapp = new Microsoft.Office.Interop.Excel.Application();
wapp.Visible = false;
wbook = wapp.Workbooks.Add(true);
wsheet = (Worksheet)wbook.ActiveSheet;
try
{

for (int i = 0; i < this.dataGridView1.Columns.Count; i++)
{
wsheet.Cells[1, i + 1] = this.dataGridView1.Columns[i].HeaderText;

}

for (int i = 0; i < this.dataGridView1.Rows.Count; i++)
{
DataGridViewRow dgvrow = this.dataGridView1.Rows[i];
for (int j = 0; j < dgvrow.Cells.Count; j++)
{
DataGridViewCell cellvalue = dgvrow.Cells[j];
try
{
wsheet.Cells[i + 2, j + 1] = (cellvalue.Value == null) ? "" : cellvalue.Value.ToString();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
wapp.Visible = true;
}
catch (Exception ex)
{
MessageBox.Show("Error Details" + ex.Message);
}
}
}
}
Author: Ultimaterengan      Posted Date: 05 Feb 2014
Export DataGridView to Excel in C#
try like this also

How to export datagridview to excel format using c#?In this article I'm going to explain how to convert datagridview to excel format using c#. This is a requirement often in many projects as users may
want to save some data generated in applications for future reference.
Just drag and drop one datagridview and button control to your window application.


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.Office.Interop.Excel;

namespace WindowsApplication1
{
public partial class Form1 : Form
{
System.Data.DataTable dtblSkill = new System.Data.DataTable();
public Form1()
{
InitializeComponent();
dtblSkill.Columns.Add("SkillCode", typeof(string));
dtblSkill.Columns.Add("SkillName", typeof(string));
AddGridViewSkillColumns();
}
private void AddGridViewSkillColumns()
{
try
{

DataGridViewTextBoxColumn dgvtxtSkillCode = new DataGridViewTextBoxColumn();
dgvtxtSkillCode.Name = "SkillCode";
dgvtxtSkillCode.DataPropertyName = "SkillCode";
dgvtxtSkillCode.HeaderText = "Skill Code";
dgvtxtSkillCode.Width = 120;


DataGridViewTextBoxColumn dgvtxtSkillName = new DataGridViewTextBoxColumn();
dgvtxtSkillName.Name = "SkillName";
dgvtxtSkillName.HeaderText = "Skill Name";
dgvtxtSkillName.DataPropertyName = "SkillName";
dgvtxtSkillName.Visible = true;
dgvtxtSkillName.Width = 160;


dataGridView1.Columns.Add(dgvtxtSkillCode);
dataGridView1.Columns.Add(dgvtxtSkillName);

dataGridView1.DataSource = dtblSkill;
}
catch (Exception ex)
{
MessageBox.Show("Error Details" + ex.Message);
}
}

private void button1_Click(object sender, EventArgs e)
{
Microsoft.Office.Interop.Excel.Application wapp;
Microsoft.Office.Interop.Excel.Worksheet wsheet;
Microsoft.Office.Interop.Excel.Workbook wbook;
wapp = new Microsoft.Office.Interop.Excel.Application();
wapp.Visible = false;
wbook = wapp.Workbooks.Add(true);
wsheet = (Worksheet)wbook.ActiveSheet;
try
{

for (int i = 0; i < this.dataGridView1.Columns.Count; i++)
{
wsheet.Cells[1, i + 1] = this.dataGridView1.Columns[i].HeaderText;

}

for (int i = 0; i < this.dataGridView1.Rows.Count; i++)
{
DataGridViewRow dgvrow = this.dataGridView1.Rows[i];
for (int j = 0; j < dgvrow.Cells.Count; j++)
{
DataGridViewCell cellvalue = dgvrow.Cells[j];
try
{
wsheet.Cells[i + 2, j + 1] = (cellvalue.Value == null) ? "" : cellvalue.Value.ToString();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
wapp.Visible = true;
}
catch (Exception ex)
{
MessageBox.Show("Error Details" + ex.Message);
}
}
}
}

Author: Ultimaterengan      Posted Date: 05 Feb 2014
How to Print Web Control using ASP.Net with C#
"The Controls collection cannot be modified because the control contains code block." To avoid this error you should copy and paste all java script codes after HTML tag.
Author: Ultimaterengan      Posted Date: 15 Oct 2013
Monthly Attendnace Report of All employees
File download not working. I'm getting below error.

403 - Forbidden: Access is denied.
You do not have permission to view this directory or page using the credentials that you supplied.
URL:-
http://www.dotnetspider.com/attachments/Resources/

Author: Ultimaterengan      Posted Date: 20 Aug 2013
Some Interview Questions for .Net technology
Really good collection...
Author: Ultimaterengan      Posted Date: 24 May 2013
Types of joins in sql server
Nice article .......keep contribute .
Author: Ultimaterengan      Posted Date: 17 May 2013
How to Get Number of Saturday's and sunday's In SQL USING CTE
Dear Friend,
Really good collection....thanks for posting such great articles....keep contributing.....
Author: Ultimaterengan      Posted Date: 17 Apr 2012
Introduction To Windows Phone 7 Project Structure - [Part-2]
Dear friend,
This is really very nice Article....

Thanks and keep contributing....
Author: Ultimaterengan      Posted Date: 05 Nov 2011
Difference between stored procedure and functions in SQL Server
Hi ,

This resources is copied from below link
http://www.allinterview.com/showanswers/86835.html

Author: Ultimaterengan      Posted Date: 02 Nov 2011
Delete VS Truncate
Hi Editors,
This is copied resource

The original resource is below link


http://www.dotnetspark.com/qa/3052-database-what-is-recorded-as-transaction.aspx

http://dba.fyicenter.com/Interview-Questions/SQL-Server-DBA/What_s_the_difference_between_DELETE_TABLE_and_T_54.html

Author: Ultimaterengan      Posted Date: 11 Aug 2011
What is View?
This is copied resource.


http://www.techiebird.com/DBInterview1.html

check Explain about View? question.


Author: Ultimaterengan      Posted Date: 04 Jul 2011
String with single quote not saved in DB
HI Friend,

Good stuff....

Continue to post such valuable articles in dotnetspider......

I tried this one its working fine.

Author: Ultimaterengan      Posted Date: 02 Oct 2010
Text box values clearing in Best way Example
HI
Really good stuff....
Author: Ultimaterengan      Posted Date: 26 Aug 2010
How to show popup window using asp.net
HI friend,
Post your question in forum section.you will get quick response.
Author: Ultimaterengan      Posted Date: 12 Aug 2010
Add Handler and Remove Handler at Runtime
Hi friend,
You can also share your codes in dotnetspider...
Author: Ultimaterengan      Posted Date: 10 Aug 2010
Interview in Software Company
Hi
Nice...

Author: Ultimaterengan      Posted Date: 15 Jul 2010
Sardar writes exam
HI
Nice one....keep try to post such good joke.....
Author: Ultimaterengan      Posted Date: 06 Jul 2010
Right Click
HI
Nice joke.......
Author: Ultimaterengan      Posted Date: 02 Jul 2010
What is LINQ?
Good...
Author: Ultimaterengan      Posted Date: 22 Jun 2010
.net interview in Polaris Chennai
Thanks for the information.............
Author: Ultimaterengan      Posted Date: 22 Jun 2010
Client side validation in javascript
HI
What error.............
Author: Ultimaterengan      Posted Date: 18 Jun 2010
How to restrict page from posting back
HI
I tried this one but its not working well.Can you give me one example for this.
Author: Ultimaterengan      Posted Date: 18 Jun 2010
How to get session value in Javascript
HI Alwyn ,
Im not force to use this one .im just telling we can use session in java script also that it.if you write any script ,it will not support all the browser.You need to write the script browser compatibility.

What kind of problem will come can you say that?
Author: Ultimaterengan      Posted Date: 08 Jun 2010
How to get session value in Javascript
Ya its correct but we can restrict right click option.
Author: Ultimaterengan      Posted Date: 08 Jun 2010
How to show popup window using asp.net
This is very simple project.if you want to show centered pop up window means,just download the below project and run it.Some times we need to show information with in pop up window in that time we will use this project code.

Author: Ultimaterengan      Posted Date: 25 May 2010
IS operator
HI Friend,
This is really Good one .........
Author: Ultimaterengan      Posted Date: 23 Feb 2010
Difference between nchar & nvarchar
HI friend,
This is really good one continue to posting such a valuable articles....
Author: Ultimaterengan      Posted Date: 22 Jan 2010
How to Use TextBoxWatermarkExtender
HI,
nice one
Author: Ultimaterengan      Posted Date: 07 Dec 2009
Bind DataSet to Radio button list
HI Meetu,
Hereafter i will correct it.


Author: Ultimaterengan      Posted Date: 08 Jul 2009
Bind DataSet to Radio button list
Hi ,
Read first line.I asked to Drag and drop the radiobuttonlist to your page

Author: Ultimaterengan      Posted Date: 08 Jul 2009
Bind DataSet to Radio button list
Hi JayaKumar,
Whether you checked my code or not?
This code working fine so......

Author: Ultimaterengan      Posted Date: 08 Jul 2009
Change DropDownList's SelectedText colour using JavaScript
Gokul,

Lots of sites have this code so why you came here,its because this site is more good one.

If you are not having guts to put resources means, go eat bun and sleep.Dont put these kind of silly messages and spoil the forum. or else you will throw out.

Regards
Thala-fan
Author: Ultimaterengan      Posted Date: 02 Jul 2009
Message box display in ASP.net
Hi friend,

Really good one continue posting such valuable articles

Thanks
Author: Ultimaterengan      Posted Date: 23 Jun 2009
to check sql is installed in our system or ont
hi da ,
Good one. post such valuable articles.....

Thanks for posting
Author: Ultimaterengan      Posted Date: 09 Jun 2009
Error Handling in Sql server 2005
good one

thanks
Author: Ultimaterengan      Posted Date: 03 Jun 2009
Ispostback in c#
nice one
Author: Ultimaterengan      Posted Date: 03 Jun 2009
Time takes u..
nice one thanks
Author: Ultimaterengan      Posted Date: 03 Jun 2009
To Clear All TextBox Controls in Web Page
Hi,

This is very useful for all
Author: Ultimaterengan      Posted Date: 01 Jun 2009
File upload control in asp.net
hi,

Thanks for posting valuable resources.
Author: Ultimaterengan      Posted Date: 31 May 2009
AJAX
AJAX stands for Asynchronous JavaScript and XML.AJAX is not a New Technology. it's a New way of combining existing technologies.
What we do in AJAX is create the Asyncronous request to webserver using javascript and xmlhttprequest object and map a function to be excuted when the response is received.
Asyncronous means the browser does not wait for server response after sending the request to server.The core component in AJAX is the XMLHTTPRequest object.
xmlhttprequest:-
its used to send request to, and receive the request from webserver.Using this object the webpage can make a request to the webserver asyncronously, and receive the response asycronously.
Even though this object is not a w3c standards.
Author: Ultimaterengan      Posted Date: 21 Feb 2009
What Is AJAX?
AJAX stands for Asynchronous JavaScript and XML.AJAX is not a New Technology. it's a New way of combining existing technologies.
What we do in AJAX is create the Asyncronous request to webserver using javascript and xmlhttprequest object and map a function to be excuted when the response is received.
Asyncronous means the browser does not wait for server response after sending the request to server.The core component in AJAX is the XMLHTTPRequest object.
xmlhttprequest:-
its used to send request to, and receive the request from webserver.Using this object the webpage can make a request to the webserver asyncronously, and receive the response asycronously.
Even though this object is not a w3c standards.
Author: Ultimaterengan      Posted Date: 21 Feb 2009
Code Snippet for sending mail through HTML
nice code
Author: Ultimaterengan      Posted Date: 03 Oct 2008
Find space occupied by a table in a database
hi,
nice code.continue to post valuable article.
Regards
G.Renganathan
www.ultimaterengan.blogspot.com
Author: Ultimaterengan      Posted Date: 09 Sep 2008

    Next Results  


Top Contributors
Today
    Last 7 Daysmore...

    Awards & Gifts

    Online Members

    More...
     
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India