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 .

  • Have you tried retrieving the file attachment via CSOM or REST? Either should get you the FileStream. – wjervis Jun 9 '16 at 16:08
  • I can retrieve attachment but not FileStream with system.IO.Stream. I can take stream with this Microsoft.SharePoint.Client.File – Bhaskar Dhone Jun 9 '16 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 '16 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 – Bhaskar Dhone Jun 9 '16 at 16:18
  • Hmm, does the returned object have a Value property? – wjervis Jun 9 '16 at 16:25
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, privacy policy and cookie policy

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