Cannot access a closed Stream

JCWEBHOST used Ask the Experts™
Hey guys, i am geting this error: Cannot access a closed Stream, while trying to send an attach email.

here my code:

public MemoryStream Ms
        get { return ms; }
        set { ms = value; }

 public string SendMail()
        string erorr = "";
            System.Net.Mail.MailMessage MailMass = new System.Net.Mail.MailMessage();

            MailMass.From = new System.Net.Mail.MailAddress("");
            MailMass.To.Add(new System.Net.Mail.MailAddress(To));
            MailMass.Subject = Subject;
            MailMass.Body = Body;
            MailMass.IsBodyHtml = true;

            MailMass.ReplyTo = new System.Net.Mail.MailAddress("");
            MailMass.Priority = System.Net.Mail.MailPriority.Normal;
            System.Net.Mail.SmtpClient smtpC = new System.Net.Mail.SmtpClient();
            System.Net.NetworkCredential basicAuthenticationInfo = new System.Net.NetworkCredential("", "ben01int");

            if (Ms != null && Pdf_name != "")
                MemoryStream open_ms = Ms;
                open_ms.Position = 0;
                using (Attachment att = new Attachment(open_ms, Pdf_name, MediaTypeNames.Application.Pdf))

            smtpC.Host = "";
            smtpC.Port = 25;
            smtpC.UseDefaultCredentials = false;
            smtpC.Credentials = basicAuthenticationInfo;

        catch (Exception E)
            erorr = E.Message.ToString();

        return erorr;

Open in new window

please help
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Hi! Where do you create and close ms?
The error is comming because MemoryStream object (ms) is closed, when you try to read or write it.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial