CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Eric Wise

Business & .NET

HowTo: Create an outlook appointment in ASP .NET Part II

What's going on here?  Check my previous post.

 

Here's how to do it without actually creating a file.  Thanks to Bogo for pointing me to the memorystream.

private void Page_Load(object sender, System.EventArgs e)

{

   System.IO.MemoryStream mStream = new System.IO.MemoryStream();

   System.IO.StreamWriter writer = new System.IO.StreamWriter(mStream);

   writer.AutoFlush = true;

   writer.WriteLine("BEGIN:VCALENDAR");

   writer.WriteLine(@"PRODID:-//Microsoft Corporation//Outlook MIMEDIR//EN");

   writer.WriteLine("VERSION:1.0");

   writer.WriteLine("BEGIN:VEVENT");

   //Fill in data

   DateTime dueDate;

   dueDate = DateTime.Parse(maintenance.DueDate);

   writer.WriteLine("DTSTART:" + dueDate.Year.ToString() + dueDate.Month.ToString() + dueDate.Day.ToString() + "T170000Z");

   writer.WriteLine("DTEND:" + dueDate.Year.ToString() + dueDate.Month.ToString() + dueDate.Day.ToString() + "T170000Z");

   writer.WriteLine("LOCATION:" + asset.Site.SiteDescription + " - " + asset.Location.LocationDescription + " - " + asset.Room.RoomDescription);

   writer.WriteLine("CATEGORIES:Maintenance");

   writer.WriteLine("DESCRIPTION;ENCODING=QUOTED-PRINTABLE:" + maintenance.MaintenanceDescription + "=0D=0A");

   writer.WriteLine("SUMMARY:" + asset.Product.ShortDescription + " Maintenance");

   writer.WriteLine("PRIORITY:3");

   writer.WriteLine("END:VEVENT");

   writer.WriteLine("END:VCALENDAR");

   Response.Clear(); // clear the current output content from the buffer

   Response.AppendHeader("Content-Disposition", "attachment; filename=Maintenance.vcs");

   Response.AppendHeader("Content-Length", mStream.Length.ToString());

   Response.ContentType = "application/download";

   Response.BinaryWrite(mStream.ToArray());

   Response.End();

}



Comments

Stefan Cullmann said:

Hi Eric,
have a look at these greate classes from Ryan Rinaldi:

VCARD:
http://blogs.geekdojo.net/ryan/archive/2004/04/28/1797.aspx
VCALENDAR: http://blogs.geekdojo.net/ryan/archive/2004/04/28/1798.aspx

I use them this way:

Integrate a Handler in your web.config
<httpHandlers>
<add verb="*" path="*.vcf" type="xxx.VCard.VcfHandler, xxx" />
httpHandlers>


namespace xxx.VCard
{
public class VcfHandler: IHttpHandler
{
#region IHttpHandler Member
public void ProcessRequest(HttpContext context)
{
VCard vcard = new VCard();
vcard.FirstName="Hans";
vcard.LastName="Testmann";
...
context.Response.ContentType="text/x-vcard";
vcard.Generate(context.Response.OutputStream);
}

public bool IsReusable
{
get { return false;}
}
#endregion

}

I call the vcard like http://myserver/mycards/id1234.vcf

# August 27, 2004 12:16 AM

Jason Haley said:

Downloading an event into Outlook
# August 28, 2004 4:58 AM

Leave a Comment

(required)  
(optional)
(required)  

Enter the numbers above:
Add
Check out Devlicio.us!

Our Sponsors