Steps
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Microsoft.SharePoint.Client;
  7. using Microsoft.SharePoint.Client.Social;
  8. namespace EmbedImageInPost
  9. {
  10. class Program
  11. {
  12. static void Main(string[] args)
  13. {
  14. // Replace the following placeholder values with the actual values.
  15. const string serverUrl = "http://gauti.sharepoint.com/sp";
  16. const string imageUrl = "http://gauti.sharepoint .com/Shared%20Documents/testimage.jpg";
  17. // Define the image attachment that you want to embed in the post.
  18. SocialAttachment attachment = new SocialAttachment()
  19. {
  20. AttachmentKind = SocialAttachmentKind.Image,
  21. Uri = imageUrl
  22. };
  23. // Define properties for the post and add the attachment.
  24. SocialPostCreationData postCreationData = new SocialPostCreationData();
  25. postCreationData.ContentText = "Look at this!";
  26. postCreationData.Attachment = attachment;
  27. try
  28. {
  29. // Get the context and the SocialFeedManager instance.
  30. ClientContext clientContext = new ClientContext(serverUrl);
  31. SocialFeedManager feedManager = new SocialFeedManager(clientContext);
  32. // Publish the post. This is a root post to the user's feed, so specify
  33. // null for the targetId parameter.
  34. feedManager.CreatePost(null, postCreationData);
  35. clientContext.ExecuteQuery();
  36. Console.Write("The post was published.");
  37. Console.ReadLine();
  38. }
  39. catch (Exception ex)
  40. {
  41. Console.Write("Error publishing the post: " + ex.Message);
  42. Console.ReadLine();
  43. }
  44. }
  45. }
  46. }
Hit F5 and check the output .
Thanks for learning in my Blogs!!!!