Skip to main content

Posts

Showing posts with the label CSOM

How to check user permissions for site using CSOM in SharePoint Online

In this article, we are going to learn, How to get the user permission on the site using csom or how to get the user permission programmatically, to get the permission of the user on a particular site we use GetUserEffectivePermissions() method in csom. In the SharePoint, user requires permission to perform any operation, when we work with provider-hosted add-ins and in some scenarios, we need to check the permission of user we use the GetUserEffectivePermissions() method and by passing the user name we get its effective permission on the site.  In this example, We have created a console application to check whether the user have edit person or not on site.  Pass the context of the site and email of the user into a method to check the permission of the user on the site. You must ensure users on the web before checking permission.  using System;   using System.Security;   using Microsoft.SharePoint.Client;   namespace PracticeC...

How to check permissions of user on sharepoint list using csom.

In this article, we are going to learn "How to check the permissions of user on SharePoint list using csom " or permissions of user using code. In provider-hosted SharePoint Add-ins, we use the csom code and to check the permission of the user on a particular list, once we get the effective permission of particular user on the SharePoint list and then by using that permission we can check the particular kind of permission like Addlistitem, Editelistitem, etc. In this example, we have created a console application to check whether the user has edit permission on the list or not.  Pass the client context, email of the user and list name on which you want to check the permission of the user. using System; using System.Security; using Microsoft.SharePoint.Client; namespace PracticeCsom {     class Program     {         static void Main(string[] args)         {            s...

How to get the Sharepoint Field Internal name by display name using CSOM

In this article we are going to learn  “how to get the sharepoint internal field name using the display name” of field. To perform any operation on the field. First we need to get field collections, every SharePoint list have fields and we can get it as FieldCollection . By iterating the field collection we can get information about all the fields. Call the method and pass the context , name of the list from which you want to get data and display name.  GetInternalFieldName( ClientContext clientContext ,string listName, string fieldDisplayName){        string fieldInternalName= " ";        var web = clientContext.Web;       clientContext.Load(web);       List listEventSource = web.Lists.GetByTitle(listName);       FieldCollection fields = listEventSource.Fields;       IEnumerable<Field> fieldsColl = clientContext.LoadQuery(fields); ...

System Update in SharePoint.

When we write code to update the SharePoint list item, we use the Client-side object model or Javascript object model. When we write the code we get two options for updating the list item  update()  and  systemupdate(). update vs system update SharePoint? update() method : When we use the update() method it updates the "Modified"  and "Modified By" column and if the Versioning option is enabled then it also updates the version column. systemupdate() : When we use systemupdate() method. this method did not update the   "Modified"  and  "Modified By"  column and Version. So when you do not want to update these columns while updating use the systemupdate() method. Let's view the code written in Jsom to update the item using the systemupdate (). function updateItem() { var clientContext = new SP.ClientContext('enter your site url'); var oList = clientContext.get_web().get_lists().getByTitle('enter title of your list...

How to check whether list item contains attachment or not using code.

To check whether the list item contains the attachment programmatically or using CSOM. Get the list item collection and then check for the attachment column. List listEvent  = web.Lists.GetByTitle(listName); clientContext.Load(listEvent, L => L.Id); CamlQuery camlQuery2 = new CamlQuery(); camlQuery2.ViewXml = "<View><Query></View></Query>"; ListItemCollection item_Coll = listEventSource.GetItems(camlQuery2); clientContext.Load(item_Coll); clientContext.ExecuteQuery(); foreach (ListItem oLstItem in item_Coll)   {   bool attachmentPresent = Convert.ToBoolean(oLstItem["Attachments"]);   if (attachmentPresent)     {             Console.WriteLine("Item is present");     }    } Happy Coding !!!!!

Read all the SharePoint User profile field using CSOM

The article shows CSOM and C# code to read all the user profile field. create a console application and copy the code below and replace the siteurl, user id and password with your sharepointURL , user id and password. You need to add three dll to run this code:- Microsoft.SharePoint.Client Microsoft.SharePoint.Client.Runtime Microsoft.SharePoint.Client.UserProfiles Add this dll and run the code. Enjoy Coding. using System; using Microsoft.SharePoint.Client; using Microsoft.SharePoint.Client.UserProfiles; using System.Security; namespace ConsoleApp1 {     class Program     {         static void Main()         {             using (ClientContext clientContext = new ClientContext(Yoursiteurl))             {                 string UName = "Your user name";               ...

Insert item in list using CSOM SharePoint

To insert item into list using csom code. You can create a consol application using visual studio and also use the code mentioned below. You can interact  with sharepoint list using JSOM,CSOM or using rest api. List operation using csom. using Microsoft.SharePoint.Client;  using System;  using System.Collections.Generic;  using System.Linq;  using System.Security;  using System.Text;  using System.Threading.Tasks;  namespace ConsoleApp1 { class Program { static void Main(string[] args) { using (ClientContext clientContext = new ClientContext("insert url upto list")) { string Uname = "Your ID"; string password = "Password";  SecureString Securepasseord = GetSecureString(password);  clientContext.Credentials = new SharePointOnlineCredentials(Uname, Securepasseord); clientContext.ExecuteQuery(); List oList = clientContext.Web.Lists.GetByTitle("metalist");  ListItemCreationInformation listCreationIn...