Steps
- Open Visual Studio in your system
- Select Console Applciation template and give as name .
- Add a Microsoft.Cleint Assembly refrence file in right side refrence tab in visual studio.
- Replace Program.cs with the source code
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Microsoft.SharePoint.Client;
- using Microsoft.SharePoint.Client.Social;
- namespace EmbedImageInPost
- {
- class Program
- {
- static void Main(string[] args)
- {
-
- const string serverUrl = "http://gauti.sharepoint.com/sp";
- const string imageUrl = "http://gauti.sharepoint .com/Shared%20Documents/testimage.jpg";
-
- SocialAttachment attachment = new SocialAttachment()
- {
- AttachmentKind = SocialAttachmentKind.Image,
- Uri = imageUrl
- };
-
-
- SocialPostCreationData postCreationData = new SocialPostCreationData();
- postCreationData.ContentText = "Look at this!";
- postCreationData.Attachment = attachment;
-
- try
- {
-
- ClientContext clientContext = new ClientContext(serverUrl);
- SocialFeedManager feedManager = new SocialFeedManager(clientContext);
-
-
- feedManager.CreatePost(null, postCreationData);
- clientContext.ExecuteQuery();
- Console.Write("The post was published.");
- Console.ReadLine();
- }
- catch (Exception ex)
- {
- Console.Write("Error publishing the post: " + ex.Message);
- Console.ReadLine();
- }
- }
- }
- }
Hit F5 and check the output .
Thanks for learning in my Blogs!!!!