hi,
Try using the following piece of code for filling the memory stream
MemoryStream memStream = new MemoryStream();
UnicodeEncoding encoding = new UnicodeEncoding();
Byte[] byteArray = encoding.GetBytes(myTemp);
memStream.Write(byteArray, 0, byteArray.GetLength(0));
memStream.Seek(0, SeekOrigin.Begin);
regards,
pradeep
theWizard1 wrote:
>The following sends my email, but the attachment is empty. The attachment
>should contain the data that is in the string that was created from the
>xmlReader.
>
>I have a stored procedure written using For XML explicit, and it returns an
>xml reader. Then the following:
>
>xmlRdr.MoveToContent();
>string myTemp = xmlRdr.ReadOuterXml();
>
>System.IO.MemoryStream memStream = new System.IO.MemoryStream();
>StreamWriter sw = new StreamWriter(memStream);
>sw.Write(myTemp);
>
>System.Net.Mail.MailMessage mail = new System.Mail.MailMessage();
>mail.From = new System.Net.Mail.MailAddress("i put my email address here");
>mail.To.Add("I put my email address here, because it is just a test");
>mail.Subject = "This is a test";
>mail.Body = "this content is in the body";
>
>System.Net.Mail.Attachment emailAttachment = new
>System.Net.Mail.Attachment(memStream, "text/xml");
>System.Net.Mime.ContentDisposition contentDispo =
>emailAttachment.ContentDisposition;
>
>contentDispo.FileName = "myFirstText.xml";
>mail.Attachments.Add(emailAttachment);
>
>System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("smtp.put
>myemailservernamehere");
>smtp.Send(mail);
>memStream.Close();
>
>The above sends the email with an attachment, but the attachment is empty.
>
>Note the xmlReader produces xml with a unique root, so no problem with the
>string. I can see the data in the string when I debug, but the attachment
>does not have it.
--
Message posted via DotNetMonster.com
http://www.dotnetmonster.com/Uwe/For...p-net/200604/1