Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Embed a Document in a post in SharePoint Server 2013 using .Net csom
WhatsApp
Gowtham Rajamanickam
9y
2.5
k
0
0
25
Blog
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
EmbedDocumentInPost
{
class
Program
{
static
void
Main(
string
[] args)
{
// Replace the following placeholder values with the actual values.
const
string
serverUrl =
"http://gauti.sharepoint.com/sp"
;
const
string
documentUrl =
"http://gauti.sharepoint.com//Shared%20Documents/fileName.docx"
;
try
{
// Get the context and the SocialFeedManager instance.
ClientContext clientContext =
new
ClientContext(serverUrl);
SocialFeedManager feedManager =
new
SocialFeedManager(clientContext);
// Get the document attachment from the server.
ClientResult<SocialAttachment> attachment = feedManager.GetPreview(documentUrl);
clientContext.ExecuteQuery();
// Define properties for the post and add the attachment.
SocialPostCreationData postCreationData =
new
SocialPostCreationData();
postCreationData.ContentText =
"Post with a document."
;
postCreationData.Attachment = attachment.Value;
// Publish the post. This is a root post to the user's feed, so specify
// null for the targetId parameter.
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();
}
}
}
}
Embed a Document in SharePoint
Net csom
SharePoint
Visual Studio
Up Next
Create Document Set In SharePoint 2013 Document Library Using CSOM
Ebook Download
View all
Getting Started with SharePoint Framework Development using TypeScript, PnP JS, and React JS
Read by 4.9k people
Download Now!
Learn
View all
Membership not found