The below code has been plucked from various files which is what i use to generate SSRS reports.
The things im not spelling out here are how to add web references to your project in VS, that is adding reference to your SSRS web service URLS.
Ive also attached code to send an email with an attachment, i would suggest altering the code here but creating classes that will be more conducive to what it is you are trying to do.
The code i've provided "should" run, but keep in mind i may have forgotten something, but this should get you started and on the right track.
Code to generate SSRS report
private static string fileName = null;
private static string historyID = null;
private static string deviceInfo = null;
private static string format = "PDF";
private static string encoding = null;
private static string mimeType = null;
private static string extension = null;
private static string[] streamIDs = null;
private static string _reportName = null;
private static string _historyID = null;
private static bool _forRendering = false;
private static Byte[] results;
private static report.Service.Reference reportService;
private static report.Execution.Reference reportExecReference;
fileName = destinationFilePath;
historyID = null;
deviceInfo = null;
format = (Path.GetExtension(destinationFilePath).ToUpper()).Replace(".", "");
encoding = null;
mimeType = null;
extension = null;
streamIDs = null;
_reportName = reportName;
_historyID = null;
_forRendering = false;
reportService = new report.Service.Reference.ReportingService2005();
reportExecReference = new report.Execution.Reference.ReportExecutionService();
reportService.Credentials = new NetworkCredential("username", "password", "DOMAIN");
reportServiceExec.Credentials = new NetworkCredential("username", "password", "DOMAIN");
reportService.Url = String.Format(@"http://{0}/reportserver/reportservice2005.asmx", iniDatabaseServer);
reportServiceExec.Url = String.Format(@"http://{0}/reportserver/reportexecution2005.asmx", iniDatabaseServer);
historyID = null;
deviceInfo = null;
format = Path.GetExtension(destinationFilePath) == ".xls" ? "Excel" : "PDF";
encoding = String.Empty;
mimeType = String.Empty;
extension = String.Empty;
report.Execution.Reference.Warning[] warnings = null;
streamIDs = null;
fileName = destinationFilePath;
_reportName = reportName;
_historyID = null;
_forRendering = false;
report.Service.Reference.ParameterValue[] _values = null;
report.Service.Reference.DataSourceCredentials[] _credentials = null;
report.Service.Reference.ReportParameter[] _parameters = null;
_parameters = reportService.GetReportParameters(_reportName, _historyID, _forRendering, _values, _credentials);
report.Execution.Reference.ExecutionInfo ei = reportServiceExec.LoadReport(_reportName, historyID);
report.Execution.Reference.ParameterValue[] parameters = new report.Execution.Reference.ParameterValue[parameterName.Count];
if (_parameters.Length > 0)
{
for (int i = 0; i < parameterName.Count; i++)
{
parameters[i] = new report.Execution.Reference.ParameterValue();
parameters[i].Label = null;
parameters[i].Name = parameterName[i];
parameters[i].Value = parameterValue[i];
}
}
reportServiceExec.SetExecutionParameters(parameters, "en-us");
results = reportServiceExec.Render(format, deviceInfo,
out extension, out encoding,
out mimeType, out warnings, out streamIDs);
using (FileStream stream = File.OpenWrite(fileName))
{
stream.Write(results, 0, results.Length);
}
Code to send an email with an attachment
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient(smptServer, portNumber);
mail.From = new System.Net.Mail.MailAddress(sendFrom);
if (sendTo.Contains(";"))
{
string[] emailAddress = sendTo.Split(';');
foreach (string emailAddr in emailAddress)
{
mail.To.Add(emailAddr);
}
}
else
{
mail.To.Add(sendTo);
}
mail.Subject = subject;
mail.Body = body;
mail.IsBodyHtml = isHTML;
System.Net.Mail.Attachment attachment;
attachment = new System.Net.Mail.Attachment(attachmentPath);
mail.Attachments.Add(attachment);
SmtpServer.Port = portNumber;
SmtpServer.Credentials = new System.Net.NetworkCredential(authUser, authPass);
SmtpServer.EnableSsl = true;
SmtpServer.Send(mail);