1

I need to send list item attachment via email whenever someone add an item to list. I am unable to send email with attachment. using SendGrid of azure as CSOM send email utility does not support attachment.

With send grid , I am unable to provide file url as it don’t accept (http://filepath ) (It only accept local path)

Is there any way to get list item attachment and convert it into system.IO.Stream

Is there any other approach or solution for this.

Implementing with Remote Event Receiver .

12
  • Have you tried retrieving the file attachment via CSOM or REST? Either should get you the FileStream.
    – wjervis
    Jun 9, 2016 at 16:08
  • I can retrieve attachment but not FileStream with system.IO.Stream. I can take stream with this Microsoft.SharePoint.Client.File Jun 9, 2016 at 16:13
  • Use the OpenBinaryStream method of Microsoft.SharePoint.Client.File. It will return a stream that you should be able to use.
    – wjervis
    Jun 9, 2016 at 16:16
  • yes I am able to. But when I am giving that stream as attachment parameter it says can not convert to System.IO.Stream Jun 9, 2016 at 16:18
  • Hmm, does the returned object have a Value property?
    – wjervis
    Jun 9, 2016 at 16:25

1 Answer 1

1

The OpenBinaryStream method of Microsoft.SharePoint.Client.File should return the file's stream:

var fileStream = attachment.OpenBinaryStream();
ctx.ExecuteQuery();

You can also use the OpenBinaryDirect method:

var fileInfo = Microsoft.SharePoint.Client.File.OpenBinaryDirect(ctx, attachment.ServerRelativeUrl);
var fileStream = fileInfo.Stream;

OpenBinaryDirect does not require an ExecuteQuery() method call.

I copied part of @VadimGremyachev's answer here for the OpenBinaryDirect bit.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.