After some analysis I have found the code for this. Just thought of sharing this. This code will be helpful if you have an invitation and want to show that in the webmail as an attachment.
foreach (AlternateView aview in mailMsg.AlternateViews)
{
if (aview.ContentType.MediaType == "text/calendar")
{
LinkButton lnkAttachment = new LinkButton();
lnkAttachment.ID = "lnkAttachment" + Count;
lnkAttachment.Text = "Meeting.ics;";
}
}
The above code is to show the meeting.ics as a link.
foreach (AlternateView aview in mailMsg.AlternateViews)
{
if (aview.ContentType.MediaType == "text/calendar")
{
Stream calendarStream = aview.ContentStream;
byte[] buffer = new byte[4096];
using (calendarStream)
{
int Count = 0;
do
{
Count = calendarStream.Read(buffer, 0, buffer.Length); stream.Write(buffer, 0, Count);
}
while (Count != 0);
}
stream.Position = 0;
byte[] fileData = stream.ToArray();
stream.Flush();
stream.Close();
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment; filename=meeting.ics");
Response.BufferOutput = true;
Response.BinaryWrite(fileData);
Response.End();
}
}
The above code is to download the ics file.