Hi all,

I want to send mail attatchment from SQL server. I have a Image field and i have stored word documemts in it. I am designing a form where an Email has to been sent with(attatchment) the word documents in the image field.

So, i am looking for code or a solution where it should retrieve the word document from SQl server and send it as an attachment with Email.

Thanks !

Pankaj

hi,

I have fetched my documents in a variable(datatype byte[]). Now when i want to as an attatchment its generate an error.

My Code is(that retrieve documents from SQL server)::

string filename = drd.GetValue(27).ToString();

byte[] imagecontent = (byte[])(drd[28]);

My code for Attachment:: mail.Attachments.Add(new Attachment(imagecontent, filename)); Error::

1. Argument '1': cannot convert from 'byte[]' to 'string'

2. The best overloaded method match for 'System.Net.Mail.Attachment.Attachment(string, string)' has some invalid arguments

Please Help me.

Thanks !

Pankaj

Thats because you need to use a stream.

private void button3_Click(object sender, EventArgs e)
    {
      byte[] buffer = Guid.NewGuid().ToByteArray(); //This simulates your buffer
      using (MemoryStream ms = new MemoryStream(buffer))
      {
        ms.Position = 0;
        ms.Seek(0, SeekOrigin.Begin);
        using (Attachment att = new Attachment(ms, "FileName.txt"))
        {
          //Send your mail message here. You have to send the message before
          //the attachment is disposed. You could also remove the using() block
          //from above and dispose of it later.
        }
      }
    }
  }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.