Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.58 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Net.Mail;
  6. using System.Text;
  7. using System.Web;
  8.  
  9. namespace SRP_Demo
  10. {
  11.    public class MeetingBuilder
  12.    {
  13.       private string sendTo;
  14.       private string subject;
  15.       private string location;
  16.       private DateTime startTime;
  17.       private DateTime endTime;
  18.       private DateTime startDate;
  19.       private DateTime endDate;
  20.  
  21.  
  22.       public MeetingBuilder( string sendTo, string subject, string location, DateTime startTime, DateTime endTime, DateTime startDate, DateTime endDate )
  23.       {
  24.          this.sendTo = sendTo;
  25.          this.subject = subject;
  26.          this.location = location;
  27.          this.startTime = startTime;
  28.          this.endTime = endTime;
  29.          this.startDate = startDate;
  30.          this.endDate = endDate;
  31.       }
  32.  
  33.       public string BuildHourlyMeeting()
  34.       {
  35.          string filePath = string.Empty;
  36.          string path = HttpContext.Current.Server.MapPath( "~/iCal/" );
  37.          filePath = string.Format( "{0}{1}.ics", path, subject );
  38.          StreamWriter writer = new StreamWriter(filePath);
  39.          writer.WriteLine( "BEGIN:VCALENDAR" );
  40.          writer.WriteLine( "VERSION:2.0" );
  41.          writer.WriteLine( "PRODID:-//hacksw/handcal//NONSGML v1.0//EN" );
  42.          writer.WriteLine( "BEGIN:VEVENT" );
  43.          string startDateTime = String.Format( "{0}T{1}", startDate.ToString( "yyyyMMdd" ), startTime.ToString( "HHmmss" ) );
  44.          string endDateTime = String.Format( "{0}T{1}", endDate.ToString( "yyyyMMdd" ), endTime.ToString( "HHmmss" ) );
  45.          writer.WriteLine( String.Format("DTSTART:{0}", startDateTime) );
  46.          writer.WriteLine( String.Format("DTEND:{0}", endDateTime) );
  47.          writer.WriteLine( String.Format("SUMMARY:{0}", subject) );
  48.          writer.WriteLine( String.Format("LOCATION:{0}", location) );
  49.          writer.WriteLine( "END:VEVENT" );
  50.          writer.WriteLine( "END:VCALENDAR" );
  51.          writer.Close();
  52.          return filePath;
  53.       }
  54.  
  55.       public string BuildDayMeeting()
  56.       {
  57.          string filePath = string.Empty;
  58.          string path = HttpContext.Current.Server.MapPath( "~/iCal/" );
  59.          filePath = string.Format( "{0}{1}.ics", path, subject );
  60.          StreamWriter writer = new StreamWriter( filePath );
  61.          writer.WriteLine( "BEGIN:VCALENDAR" );
  62.          writer.WriteLine( "VERSION:2.0" );
  63.          writer.WriteLine( "PRODID:-//hacksw/handcal//NONSGML v1.0//EN" );
  64.          writer.WriteLine( "BEGIN:VEVENT" );
  65.          string startDay = String.Format( "VALUE=DATE:{0}", startDate.ToString( "yyyyMMdd" ));
  66.          string endDay = String.Format( "VALUE=DATE:{0}", endDate.ToString( "yyyyMMdd" ) );
  67.          writer.WriteLine( String.Format( "DTSTART;{0}", startDay ) );
  68.          writer.WriteLine( String.Format( "DTEND;{0}", endDay ) );
  69.          writer.WriteLine( String.Format( "SUMMARY:{0}", subject ) );
  70.          writer.WriteLine( String.Format( "LOCATION:{0}", location ) );
  71.          writer.WriteLine( "END:VEVENT" );
  72.          writer.WriteLine( "END:VCALENDAR" );
  73.          writer.Close();
  74.          return filePath;
  75.  
  76.       }
  77.  
  78.       public void SendMeeting()
  79.       {
  80.          var msg = new MailMessage();
  81.          var smtpClient = new SmtpClient( "mail.bsasoftware.com" );
  82.          msg.From = new MailAddress( "BSartele@bsasoftware.com" );
  83.          msg.To.Add( "sarteleb@gmail.com" );
  84.          msg.Subject = subject;
  85.          Attachment attachment = new Attachment( BuildDayMeeting() );
  86.          msg.Attachments.Add( attachment );
  87.          smtpClient.Send( msg );
  88.       }
  89.  
  90.    }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement