csom – Authentication at Sharepoint Online stops working

I have a C # app with CSOM (latest version v16.1.19223.1200) and it worked fine until around mid-August 2019. I checked if the current password is still valid.


using (var context = new ClientContext(SharepointFolder))
    // Can't use current user, tried workaround linked from https://sharepoint.stackexchange.com/questions/176375/use-current-users-credentials-for-sharepoint-online-c

    var creds = System.IO.File.ReadAllLines(Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "creds.txt"));
    string userUpn = creds(0);
    // var spassword = new System.Net.NetworkCredential(userUpn, creds(1)).SecurePassword; // tried this as well
    var spassword = new SecureString();
    foreach (char c in creds(1)) { spassword.AppendChar(c); }
    context.Credentials = new SharePointOnlineCredentials(userUpn, spassword);

    Utils.Log.Info($"Getting page list from {context.Url}");

    var pagesList = context.Web.Lists.GetByTitle("Pages");
    context.ExecuteQuery();  ///// throws: Microsoft.SharePoint.Client.IdcrlException  HResult=0x80048821  Message=The sign-in name or password does not match one in the Microsoft account system.

    // ...

I have traced this with Fiddler and basically:

#   Result  Protocol Host                       URL
2   401     HTTPS   microsoft.sharepoint.com    /   <<<<<<<<<< Why not the path I provided in SharepointFolder?
3   502     HTTP    msoid.microsoft.com         /FPUrl.xml  
5   200     HTTPS   login.microsoftonline.com   /GetUserRealm.srf
7   200     HTTPS   msft.sts.microsoft.com      /adfs/services/trust/2005/usernamemixed
8   200     HTTPS   login.microsoftonline.com   /rst2.srf

Tracking Fiddler with browser access to the same address gives me first access SharepointFolder, is redirected for authentication and works fine.

How do I install the List View command-set extension in a site collection after deploying it with CSOM in an App Catalog?

I've created a Listview command extension with SPFX and added it to the App Catalog. Now I want to install this extension only for certain sites. I tried to add it as a custom action, but it does not work. Any help would be appreciated.

csom – Denied access to list after permissions have been granted to a group in a list

After giving View / Add / Edit / Open / Delete ListItems for a group in a list, the users of the group continue to be denied access when they try to access the list.
Here's the code I used to grant permissions:

var group = clientContext.Web.SiteGroups.GetById(id);   

 BasePermissions permissions = new BasePermissions();

 RoleDefinitionCreationInformation rdcInfo = new 
 rdcInfo.Name = "roleDefName";
 rdcInfo.Description = "Description";
 rdcInfo.BasePermissions = permissions;
 RoleDefinition roleDefinition = 

 RoleDefinitionBindingCollection RoleDefinitionBindingColl = new 

 List targetList = web.Lists.GetByTitle(listTitle);
 targetList.BreakRoleInheritance(true, false);
 RoleAssignmentCollection collRoleAssign = targetList.RoleAssignments;
 RoleAssignment rollAssign = collRoleAssign.Add(group, 

 web.RoleAssignments.Add(group, RoleDefinitionBindingColl);

Use PowerShell to connect to Project Online with CSOM under MFA

I am trying to interact with a PWA on a tenant for whom I have no choice but to use MFA. I'm trying to use the OfficeDev PnP library, which supports MFA, but can not use it for Project Online.

These works, but does not support MFA

$siteURL = "https://mytenant.sharepoint.com/sites/pwa"
$username = "my.name@mytenant.onmicrosoft.com"
$password = Read-Host -Prompt "Enter password" -AsSecureString
$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $password)
# Create & configure a client context connection
$pctx.Credentials = $credentials
# ...load stuff

This uses Office Dev PnP to obtain an MFA-friendly authentication context it does not work (I get a 403 on the $pctx.ExecuteQuery())

$authmgr = new-object OfficeDevPnp.Core.AuthenticationManager
$pctx = New-Object Microsoft.ProjectServer.Client.ProjectContext($siteUrl)
$pctx.Credentials = $authmgr.GetWebLoginClientContext($siteURL).Credentials
# ...load stuff

This latter method works well for a simple SharePoint Online ClientContext. Maybe that's the problem $authmgr.GetWebLoginClientContext($siteURL) returns a ClientContext, not a ProjectContext.


  • Try according to Gautam's suggestion $pctx = $authmgr.GetWebLoginClientContext($siteURL): This fails when running a query to load projects No overload was found for "Load" and the number of arguments: "1" Embassy. Here I believe that $ pctx does not know that it should be a ProjectContext, and that it is still a ClientContext (therefore, nothing has done the ProjectServer CSOM).

For completeness, here's the full code I've tried here:

# Load libraries
$PNPPath = "C:PathToPnP"
Add-Type –Path "$PNPPathMicrosoft.SharePoint.Client.dll"
Add-Type –Path "$PNPPathMicrosoft.SharePoint.Client.Runtime.dll"
Add-Type -Path "$PNPPathMicrosoft.ProjectServer.Client.dll"
Add-Type -Path "$PNPPathOfficeDevPnP.Core.dll"

# do stuff
$siteURL = "https://mytenant.sharepoint.com/sites/pwa"
$authmgr = New-Object OfficeDevPnp.Core.AuthenticationManager
$pctx = $authmgr.GetWebLoginClientContext($siteURL)    
$projects = $pctx.Projects
  • I also tried to convert the ClientContext directly into a ProjectContext $pctx = (Microsoft.ProjectServer.Client.ProjectContext)$authmgr.GetWebLoginClientContext($siteURL) but this fails with a Can not convert … Error.

sharepoint online – Should I use Microsoft Graph or CSOM when integrating .NET in O365?

I have an existing integration based on CSOM that I need to switch from one .NET solution to another. I realized that Microsoft now has a Graph API. I've tried to research recommendations for using the Graph API or CSOM, but I have not found any documentation that I thought was sufficiently meaningful on this topic.

The use case retrieves calendar events from O365.

Should we choose to use the Microsoft Graph API or the CSOM NuGet package? Or is there another alternative that should be used for integration? I do not just want to use CSOM because we have it when it's considered a bit dated.

I'm inexperienced when it comes to integration with Sharepoint / O365.

csom – The object returned by the following call stack is null. ListItemAllFields AddWithOverwrite folder

I'm working on the migration tool with SharePoint CSOM from file system to sharepoint.
Everything worked fine, until now I have a new exception for some of the folders below.

The method can not be called or the property can not be retrieved from the null object. object
The value returned by the following call stack is null. ListItemAllFields
AddWithOverwrite Folders at
Microsoft.SharePoint.Client.ClientRequest.ProcessResponseStream (Stream
Microsoft.SharePoint.Client.ClientRequest.ProcessResponse ()

in the bottom line

CreatedFolder = ParentSPFolder.Folders.AddWithOverwrite(DestPath, true);

I have already read the questions below, but have not found my case.

The method can not be called or the property can not be retrieved from the null object. The object returned by the following call stack is null. "File " "

Server Exception: Method can not be called or property can not be obtained from null object. The object returned by the following call stack is null. "File " "

Can you please tell me what's wrong with the code?

Thank you.

SharePoint Online – PowerShell – CSOM ExecuteQuery Exception: Root element is missing

I'm used to working with local SharePoint environments, but now I'm trying to familiarize myself with SharePoint Online. I can connect to my tenant using Connect-SPOService and use the default SharePoint Online cmdlets so that my credentials work and the access path seems to be fine.

However, for the work I need to do, I have to use the more extensive utility of CSOM. At first, I was just trying to set up a simple PowerShell procedure to learn some of the basics of using CSOM with SharePoint Online. However, I still have a problem with ClientContext.ExecuteQuery. It always fails with the error "Root element missing". I am not sure if this is because the query does not retrieve data or anything else related to my environment.

I currently have my own SharePoint tenant with some initial websites and lists. I am the only user and administrator. Everything is still very simple. I have installed and imported the following modules (using PSGallery) to set my PS environment (and sessions). I think I have identified everything I need, but it is quite possible that I miss something important.

            Name of the module type version
---------- ------- ----
Binary 16.0.90 ... Microsoft.Online.SharePoint.PowerShell
Manifest Microsoft.PowerShell.Management
Manifest Microsoft.PowerShell.Security
Manifest Microsoft.PowerShell.Utility
Script 1.2 PSReadline
Script 1.0.0 SharePointOnline.CSOM
Binary 3.11.19 ... SharePointPnPPowerShellOnline
Script 2.1.6 SharePointSDK

I am working in Windows 10 with PowerShell 5.1 (running as administrator). Everything is still very simple, but I can not pass the query execution to load the web context so I can start doing extra things.

I've found many online examples of PowerShell / CSOM to connect to websites and set the context. I've tried them all (at least that's how it seems to me), but so far nothing has worked. I can not find anything else to try or take additional diagnostic steps. Therefore, I would be glad to receive suggestions at this point.

Here is a PS session log of one of my test runs with the error message at the end …

PS C:> $ LibPath = "C:  Program Files  WindowsPowerShell  Modules  SharePointOnline.CSOM  1.0.0"
PS C:>[System.Reflection.Assembly]:: LoadFile ("$ LibPath  Microsoft.SharePoint.Client.dll")
Location of the GAC version
--- ------- --------
False v4.0.30319 C:  Program Files  WindowsPowerShell  Modules  SharePointOnline.CSOM  1.0.0  Microsoft.SharePoint.Cl ...

PS C:>[System.Reflection.Assembly]:: LoadFile ("$ LibPath  Microsoft.SharePoint.Client.Runtime.dll")
Location of the GAC version
--- ------- --------
False v4.0.30319 C:  Program Files  WindowsPowerShell  Modules  SharePointOnline.CSOM  1.0.0  Microsoft.SharePoint.Cl ...

PS C:>[System.Reflection.Assembly]:: LoadFile ("$ LibPath  Microsoft.SharePoint.Client.UserProfiles.dll")
Location of the GAC version
--- ------- --------
False v4.0.30319 C:  Program Files  WindowsPowerShell  Modules  SharePointOnline.CSOM  1.0.0  Microsoft.SharePoint.Cl ...

PS C:>
PS C:> # Try a simple connection test
PS C:> Write-Host "Start connection test ..."
Start connection test ...

PS C:>
PS C:> $ UserName = "xxxxxxx@xxxxxx.onmicrosoft.com"
PS C:> $ SiteUrl = "https://xxxxxx.sharepoint.com/sites/Testing"
PS C:> $ ctx = New Object Microsoft.SharePoint.Client.ClientContext ($ SiteUrl)
PS C:>
PS C:> $ pwd = Read Host Prompt "Enter Password" -AsSecureString
Enter password: **********
PS C:> $ securePwd = ConvertTo-SecureString $ pwd -AsPlainText -Force
PS C:>
PS C:> $ Cred = New Object Microsoft.SharePoint.Client.SharePointOnlineCredentials ($ UserName, $ securePwd)
PS C:>
PS C:> $ ctx.credentials = $ Cred
PS C:> if (! $ Ctx.ServerOjectIsNull.Value)
Write-Host "Connected to $ SiteUrl" -ForegroundColor Green
Connected to https://xxxxxx.sharepoint.com/sites/Testing

PS C:>
PS C:> $ web = $ ctx.Web
PS C:> Write-Host "context is $ ctx"
The context is Microsoft.SharePoint.Client.ClientContext

PS C:> Write Host "Web is $ web"
The Web is Microsoft.SharePoint.Client.Web

PS C:> $ ctx.Load ($ web)
PS C:> $ ctx.ExecuteQuery ()

** Exception when calling "ExecuteQuery" with "0" arguments: "Root element missing."
In the line: 1 character: 1
+ $ ctx.ExecuteQuery ()
+ CategoryInfo: Not specified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId: XmlException **

sharepoint online – CSOM, GroupBy, certain ViewFields and system fields

From my SP library, I would need to get a list of the MeetingID grouped by MeetingID.
I have tried several times with CAML, but it did not work:

CamlQuery query = new CamlQuery ();
query.ViewXml = @ "  
                                                        2016-01-01T15: 55: 52Z           

ListItemCollection items = list.GetItems (query);
cc.Load (items, o => o.Include (p => p["MeetingID"]));
cc.ExecuteQuery ();

Since the CAML returns the MeetingID and many system fields, I had to use those Include Syntax. However, none of my 1500 entries in SP were grouped (I should only have 50 unique MeetingIDs). Again, probably in the context of the system fields that prevent the occurrence of grouping …

I also tried:

cc.Load (items, o => o.Include (p => p["MeetingID"]) .GroupBy (g => g["MeetingID"]));

But this one returns an error …

I also tried to see if a property is similar Viewfield Only There are in CSOM, but it does not seem to be the case.

Your help is appreciated

Set item-level permissions for a SharePoint Online library using CSOM PowerShell

I'm using this script below to upload a file or multiple files to a document library in Sharepoint Online. I just want to set the "Read" permission so only a specific user can read (see) the file.

How can I first set the read permission for a particular domain user and then upload the file?

Why? -> I want to create a Payroll 2019 folder and then upload a paycheck and set the permissions so that employees can only see their personal paychecks.

I can also create a folder for each employee and set read permission at the folder level. However, I prefer to give all employees access to "paychecks 2019" and give them file-level permissions during the upload.

Add-Type Path "C:  Program Files  Common Files  Microsoft Shared  Web Server Extensions  15  ISAPI  Microsoft.SharePoint.Client.dll"
Add-Type Path "C:  Program Files  Common Files  Microsoft Shared  Web Server Extensions  15  ISAPI  Microsoft.SharePoint.Client.Runtime.dll"

$ Context = New-Object Microsoft.SharePoint.Client.ClientContext ($ SiteURL)
$ Creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials ($ User, $ Password)
$ Context.Credentials = $ Creds

$ List = $ Context.Web.Lists.GetByTitle ($ DocLibName)
$ Context.Load ($ List.RootFolder)
$ Context.ExecuteQuery ()

$ TargetFolder = $ Context.Web.GetFolderByServerRelativeUrl ($ List.RootFolder.ServerRelativeUrl + "/" + $ FolderName);

Foreach ($ File in (dir $ Folder-File))
$ FileStream = New-Object IO.FileStream ($ File.FullName,[System.IO.FileMode]::To open)
$ FileCreationInfo = New object Microsoft.SharePoint.Client.FileCreationInformation
$ FileCreationInfo.Overwrite = $ true
$ FileCreationInfo.ContentStream = $ FileStream
$ FileCreationInfo.URL = $ File
$ Upload = $ TargetFolder.Files.Add ($ FileCreationInfo)
$ Context.Load ($ Upload)
$ Context.ExecuteQuery ()