CSOM
15 TopicsUpdating Editor field on SharePoint Online using the CSOM with App Only Auth
I have the following issue. I work with CSOM and I want to update the Author and Editor field on a List Item object. The actual problem is that the Editor is not updated and the value is set to the SharePoint App user. The problem occurs after using the App Only Authentication. The following method is used to update Author, Editor, Creation Date and Modified Date. List<SP.ListItemFormUpdateValue> values = new List<SP.ListItemFormUpdateValue>(); foreach (ItemProperty property in properties) { property.AddPropertyToUpdateList(ctx, item, info, values); } IList<SP.ListItemFormUpdateValue> results = item.ValidateUpdateListItem(values, true, string.Empty); ctx.ExecuteQuery(); info.Log("<--// Called \'ValidateUpdateListItem\'. //-->"); // check for API-failures. CheckErrors(results); Do you have any ideas why this is not working for Editor but for Author-it works? I also tried to use the Update method to edit the Author and Editor, but this is also not working for the Author field. User user = service.Ctx.Web.EnsureUser("email address removed for privacy reasons"); ctx.Load(user); ctx.ExecuteQuery(); FieldUserValue userValue = new FieldUserValue(); userValue.LookupId =user.Id; item["Editor"] = userValue; item["Author"] = userValue; item.Update(); ctx.ExecuteQuery();4.2KViews0likes3CommentsUsing App Password to login to SharePoint Online CSOM
Is it possible to use app passwords to login to SharePoint Online CSOM based scripts? We need to run scripts unattended and thus, using Pnp web login is not an option. Anyone know of workarounds to run CSOM scripts unattended. Our scripts need SharePoint administrator permissions as it uses user profile bulk update API.4.1KViews0likes1CommentAdd to PnP Provisioning template using CSOM
I am currently creating a console application using the PnP provisioning engine. I'd like to be able to add a list to the template in memory using CSOM as per https://github.com/SharePoint/PnP-Guidance/blob/master/articles/provisioning-console-application-sample.md template.Lists.Add(new ListInstance() { Title = "PnP Sample Contacts", Url = "lists/PnPContacts", TemplateType = (Int32)ListTemplateType.Contacts, EnableAttachments = true }); What I can't figure out is how to do the content type bindings.Solved3.1KViews1like5CommentsIssue Setting Domains AllowList for Sharing in CSOM API
Hi all We found an issue trying to set allowed domains for sharing through CSOM. When setting the site property's SharingDomainRestrictionMode to AllowList and setting the SharingAllowedDomainList all queries are executed without error, however when looking at the sharing settings in SharePoint the "Limit external sharing by domain." checkbox is checked, but the mode is set to "Don't allow sharing with users from these blocked domains" and no domains are in the list. The BlockList SharingDomainRestrictionMode works, and the SharingBlockedDomainList can be set. SharingDomainRestrictionMode None also works, only the AllowList does not work as intended. Does anyone have any idea what's going on here? var siteProperties = tenant.GetSitePropertiesByUrl(siteCollectionUrl, false); ctx.Load(siteProperties, s => s.SharingDomainRestrictionMode, s => s.SharingAllowedDomainList); ctx.ExecuteQueryRetry(); siteProperties.SharingDomainRestrictionMode = SharingDomainRestrictionModes.AllowList; siteProperties.SharingAllowedDomainList = domainString; siteProperties.Update(); ctx.ExecuteQueryRetry();Solved2.3KViews0likes4CommentsCSOM SystemUpdate() cannot update Editor field
In a SharePoint Online Document Library I've a file that is in published status (version x.0). I am updating various fields of this file with the listItem.SystemUpdate() command. I need this sort of update because is the only one that can be used on a published file that not increase the version. (UpdateOverrideVersion return an error on published documents) When I try to update the Editor fields this is not updated. (_currentItem is a File object) var user = _ctx.Web.EnsureUser(publishinfo.currentUser_email); _ctx.Load(user); _ctx.ExecuteQuery(); _currentItem.ListItemAllFields["Editor"] = user; _currentItem.ListItemAllFields.SystemUpdate(); _ctx.ExecuteQuery(); All other fields of the item can be updated. "Editor" and "Modified" are the only two that are not working. (Author for example is correctly updated in this way) Any idea? Thanks2.2KViews0likes1CommentCSOM error WASSN_ACTUALS_PENDING IS NULL
I'm currently developing a Project Online client application using CSOM. When i'm requesting the Task Assignments i'm receiving the following error with some projects: The value for column 'WASSN_ACTUALS_PENDING' in table 'Assignments' is DBNull. I've already checked out and published the project but it doesn't help. Any suggestions how to solve this?1.9KViews0likes5CommentsRetryQuery not working after throttling
Hi everyone, We are using the recommended approach for throttling. Here is the method we are using to execute the requests: public void ExecuteQueryWithRetry(ClientContext ctx, int retryCount, int backOffInterval, ILog LOG) { DateTime startTimeStamp = DateTime.Now; try { int retryAttempts = 0; int retryAfterInterval = 0; bool retry = false; ClientRequestWrapper wrapper = null; LOG.Debug($"Client Context: {ctx.GetHashCode()}"); LOG.Debug($"Throttled : {Throttled}"); if (Throttled) { while (Throttled) { LOG.Debug("Still throttled..."); Thread.Sleep(100); } Thread.Sleep(new Random().Next(500)); LOG.Debug("Throttled finished"); } while (retryAttempts < retryCount) { try { if (retry && wrapper != null && wrapper.Value != null) { LOG.Debug("Execute request with wrapper value..."); ctx.RetryQuery(wrapper.Value); LOG.Debug("Execute request with wrapper value finished"); Throttled = false; return; } else { LOG.Debug("Execute request..."); ctx.ExecuteQuery(); LOG.Debug("Execute request finished"); Throttled = false; return; } } catch (WebException ex) { var response = ex.Response as HttpWebResponse; // Check for throttling if (response != null && (response.StatusCode == (HttpStatusCode)429 || response.StatusCode == (HttpStatusCode)503)) { Throttled = true; wrapper = (ClientRequestWrapper)ex.Data["ClientRequest"]; retry = true; string retryAfterHeader = response.GetResponseHeader("Retry-After"); if (!string.IsNullOrEmpty(retryAfterHeader)) { if (!Int32.TryParse(retryAfterHeader, out retryAfterInterval)) { retryAfterInterval = backOffInterval; } } else { retryAfterInterval = backOffInterval; } LOG.Warn($"We got throttled! Will back off for {retryAfterInterval} seconds."); } else { LOG.Debug(ex.StackTrace); throw; } } Thread.Sleep(retryAfterInterval * 1000); retryAttempts++; } throw new MaximumRetryAttemptedException($"Maximum retry attempts '{retryCount}' has been attempted."); } finally { if (LOG.IsDebugEnabled) { TimeSpan duration = DateTime.Now - startTimeStamp; LOG.Debug($"Executed CSOM query in [{duration.TotalMilliseconds.ToString("0.00")}] ms"); } } } We got the 429 error and after that we wait the recommended time until we execute again the request. The request is re-executed using the RetryQuery method. After the method is called, we got no error but the request is not executed. Do you have any ideas why we encounter this problem?1.8KViews0likes2CommentsMethod Not Found when running the application after some Windows updates
Hi everybody, After some Windows updates, I encountered a really annoying error. I don't have any compile errors, but when I run the application I get 'Method Not Found' error. Method not found: 'System.Collections.Generic.IList`1<Microsoft.SharePoint.Client.ListItemFormUpdateValue> Microsoft.SharePoint.Client.ListItem.ValidateUpdateListItem(System.Collections.Generic.IList`1<Microsoft.SharePoint.Client.ListItemFormUpdateValue>, Boolean, System.String)' I checked the ListItem class and the method is there. We are using the Microsoft.SharePoint.Client, Version=15.0.0.0. Do you have any idea what could be the problem? Thanks, Cristina.Solved1.6KViews0likes1CommentRight User Permissions to use ListItem.GetUserEffectivePermissions method
I'm currently using a SharePoint account as a Service account to get files and share them in an application I'm working on using CSOM. I filter the files according to the logged-in user to check if the user has no access to the file, then I hide it, to prevent him from trying to access it and get "Permission Denied" error. So, I used ListItem.GetUserEffectivePermissions for this issue, but I need to grant the user only the permissions he needs to access and make that check. I checked the official documentation of ListItem.GetUserEffectivePermissions https://learn.microsoft.com/en-us/previous-versions/office/sharepoint-csom/ee536458(v=office.15) but unfortunately, I found no direct clue which permission does the job. So to recap what this service account needs to do is : Execute Search across all sharepoint files [SearchExecutor]. Get Login Name by Email using Utility.ResolvePrincipal (to be used in GetUserEffectivePermissions function). Use GetUserEffectivePermissions to check if the logged-in User has permission to view the file. I'd really appreciate your help as I'm kind of new to SharePoint and I searched a lot but found no clue about what I need.1.5KViews0likes1CommentMicrosoft.SharePoint.Client.CheckedOutFile - TakeOverCheckOut Not working (CSOM 16.1.7521.1200)
I trying to "Take Ownership" of the files which are in "No checked in version" by using latest CSOM version 16.1.7521.1200 from SharePoint Online. I am using App Only token to do execute this method. It didn't throw any exception but changes "Checkoutby" user to "SharePoint App" and file remains in same state (No Checked in version) Please help me to resolve this. Code: string siteurl ="https://<site>.sharepoint.com" Uri siteUri = new Uri(siteurl); string realm = TokenHelper.GetRealmFromTargetUrl(siteUri); string token = TokenHelper.GetAppOnlyAccessToken(TokenHelper.SharePointPrincipal, siteUri.Authority, realm).AccessToken; clientContext = TokenHelper.GetClientContextWithAccessToken(siteUri.ToString(), token); List list = web.GetListByTitle("LibraryName"); checkedOutFiles = list.GetCheckedOutFiles(); clientContext.Load(checkedOutFiles); clientContext.ExecuteQueryRetry(); foreach (var file in checkedOutFiles) { try { Console.WriteLine("Getting Checked out file " + file.ServerRelativePath.DecodedUrl); file.TakeOverCheckOut(); clientContext.ExecuteQueryRetry(); } catch (Exception ex) { Console.WriteLine(ex.Message); } }1.5KViews0likes0Comments