SendGrid.Net.Mail.Attachment.CreateAttachmentFromString C# (CSharp) Method

CreateAttachmentFromString() public static method

public static CreateAttachmentFromString ( string content, string name, Encoding contentEncoding, string mediaType ) : Attachment
content string
name string
contentEncoding System.Text.Encoding
mediaType string
return Attachment
        public static Attachment CreateAttachmentFromString(string content, string name, Encoding contentEncoding, string mediaType)
        {
            if (content == null)
                throw new ArgumentNullException("content");
            MemoryStream ms = new MemoryStream();
            StreamWriter sw = new StreamWriter(ms, contentEncoding);
            sw.Write(content);
            sw.Flush();
            ms.Position = 0;
            Attachment a = new Attachment(ms, name, mediaType);
            a.TransferEncoding = ContentType.GuessTransferEncoding(contentEncoding);
            //a.ContentType.CharSet = sw.Encoding.BodyName;
            return a;
        }

Same methods

Attachment::CreateAttachmentFromString ( string content, ContentType contentType ) : Attachment
Attachment::CreateAttachmentFromString ( string content, string name ) : Attachment