Is it possible to convert string[] to byte[]? I'm trying to send ICS file but I want to avoid saving it on server and retrieving it back. Here is the code I have so far and it breaks while trying to convert to bytes[]
string schLocation = "Conference Room";
string schSubject = "Business visit discussion";
string schDescription = "Schedule description";
System.DateTime schBeginDate = Convert.ToDateTime("7/13/2014 10:00:00 PM");
System.DateTime schEndDate = Convert.ToDateTime("7/13/2014 11:00:00 PM");
//PUTTING THE MEETING DETAILS INTO AN ARRAY OF STRING
String[] contents = { "BEGIN:VCALENDAR",
"PRODID:-//Flo Inc.//FloSoft//EN",
"BEGIN:VEVENT",
"DTSTART:" + schBeginDate.ToUniversalTime().ToString("yyyyMMdd\\THHmmss\\Z"),
"DTEND:" + schEndDate.ToUniversalTime().ToString("yyyyMMdd\\THHmmss\\Z"),
"LOCATION:" + schLocation,
"DESCRIPTION;ENCODING=QUOTED-PRINTABLE:" + schDescription,
"SUMMARY:" + schSubject, "PRIORITY:3",
"END:VEVENT", "END:VCALENDAR" };
//byte[] data = contents.Select(x => Byte.Parse(x)).ToArray();
byte[] data = contents.Select(x => Convert.ToByte(x, 16)).ToArray();
MemoryStream ms = new MemoryStream(data);
MailMessage message = new MailMessage("[email protected]", "[email protected]");
message.Subject = schSubject;
message.Body = "This is test";
message.IsBodyHtml = false;
message.Attachments.Add(new Attachment(ms, "meeting.ics"));
SmtpClient client = new SmtpClient(ConfigurationManager.AppSettings["SmtpServer"]);
client.Send(message);
I get a following error: Additional non-parsable characters are at the end of the string.