Author Archives: roel

Create Folder with Content Type Programmatically in SharePoint 2013 using client side (CSOM)

How to Get Library Name via Url Programmatically in SharePoint 2013 using client side (CSOM)

Just like site name, sometimes or most of the time, the url is different from the name of the library.
For example:
The url will be like “http://roel2013/sites/t1/lib1” but the library name is “library”
So we must not rely on the url for the library name.
To get the library name programatically, use the code below.

but this will only work if the url ends in a library url, what if the end of the url is folder or docset?
or a folder within a folder within a folder?
Have no fear, the ghostbusters are here.
Use the code below.

How to Get Site name Programmatically in SharePoint 2013 using client side (CSOM)

This might be pretty basic, but it’s good to know 🙂
Sometimes or most of the time, the url is different from the name of the site.
For example:
The url will be like “http://roel2013/sites/t1” but the site name is “testing”
So we must not rely on the url for the site name.
To get the site name programatically, use the code below.

How to Get Followed Sites Programmatically in SharePoint 2013 using client side (CSOM)

Add as Reference
Microsoft.SharePoint.Client.UserProfiles.dll

Add using
using Microsoft.SharePoint.Client.Social;

SocialFollowingManager is the key to check the followed sites

How to UnFollow Site or Stop Following Sites Programmatically in SharePoint 2013 using client side (CSOM)

Add as Reference
Microsoft.SharePoint.Client.UserProfiles.dll

Add using
using Microsoft.SharePoint.Client.Social;

SocialFollowingManager is the key to check the followed sites

How to Follow Site Programmatically in SharePoint 2013 using client side (CSOM)

Add as Reference
Microsoft.SharePoint.Client.UserProfiles.dll

Add using
using Microsoft.SharePoint.Client.Social;

SocialFollowingManager is the key to check the followed sites

Get ContentType Id base on ContentType Name(s)

Check if file exists in subfolder without using an exception

If you check the blog post in “Check if file exists in list/library without using an exception”
the method here is somewhat similar, with some few additional tricks

Here we need serverRelativeUrl variable

The key here is in the xmlQuery, we added Scope=’RecursiveAll’, which looks entirely in a library, but we will limit the search only to our location with

and {1} is the serverRelativeUrl

Check if file exists in list/library without using an exception

This is all well and good, but this won’t work if the file is in subfolder.
See “Check if file exists in subfolder without using an exception”

Get Columns or Fields of a Content Type

Get Content Type of a File or Folder in a List/Library

If it’s a folder, replace the filename with a folder name

Get Content Type of a List/Library

Add Multiple Content Type to a Library within a subsite

I have encountered a scenario where I need to add a content type from a library, but the library is within a subsite and the content types are defined at the root.

Using my code here won’t work because the content type can’t be (for lack of better word) access in a subsite. You can see it in the browser but it is like a hologram, you can see it but you can’t touch it.

So how do we solve this issue?
We use the context.Site.RootWeb.ContentTypes

See below code in action.

Check user permission

Hide Content Type Columns of a Library/List

Create Document Set in the library/list

Set Default Value on Library/List Columns

Delete “All Documents” View

Add Multiple Content Type to Library base on Content Type Group

Get ContentType Ids of the Content Type Base from Content Type Group

Check if Library or List exists without using Exception

Look Ma, no exception!!! 🙂

How to Create View Programmatically in SharePoint 2013 using client side (CSOM)

or for multiple views you can do this

for the viewFields list, it is listed below.
Sorry if it’s all messed up, still looking for a better way to display this.

Or you can check it over here, a lesser messed up than my list but still messed up 😀

Set Default Content Type Programmatically in SharePoint 2013 using client side (CSOM)

Hide Columns of Content Type Programmatically in SharePoint 2013 using client side (CSOM)

Below is the awesome code, easy peasy.

How to delete the content type from the list using CSOM in SharePoint 2013

Tried using this but won’t work if the Content Type is the default “Document” Content type, and the Id is hard coded.

In real life, real world application, you won’t hard code an Id.

The next code is the one I use and is much more robust and effective. It works on any content type as well as the built in “Document” content type.

Welcome

Welcome to my blog.
I am a Microsoft Certified Professional in C# with more than 10 yrs experience in Microsoft technology developing and designing different enterprise applications.
My specialty is developing SharePoint application in client side object model.
This blog will contain SharePoint codes and techniques which I’ve learnt while developing SharePoint applications.
Hope this blog will be helpful for you.
Enjoy reading and learning.