There are a lot of other discussions on AllowUnsafeUpdates
, but none mention SharePoint Online. Is AllowUnsafeUpdates
available in SharePoint Online? If not, are there alternatives or manual actions to achieve the same? Thank you.
-
2no not available. No alternatives. Why do you need that ?– Gautam ShethCommented Mar 22, 2018 at 11:19
-
@GautamSheth, Thank you. Understood. I want to update 'Author' filed in a list through CSOM. On my test site (online) code works perfectly. But client (online) reports errors on setting this field. I thought that it is related to my site settings and thought about this option as a first candidate. By the way, you clearly answered my simple question. You might post it as an answer.– Boris ZinchenkoCommented Mar 22, 2018 at 11:22
2 Answers
AllowUnsafeUpdates
property is not available in CSOM.
There are no alternatives for that as well.
To update author column as per your comment, you can try something as below:
Microsoft.SharePoint.Client.User user = context.Web.EnsureUser("i:0#.f|membership|[email protected]");
context.Load(user);
context.ExecuteQuery();
FieldUserValue userValue = new FieldUserValue();
userValue.LookupId = user.Id;
listItem["Author"] = userValue;
listItem.Update();
context.ExecuteQuery();
-
1Thank you for the code. I have roughly same, which works fine for me but not for client. I will ship this code to client and get feedback. I cannot check it myself because on my side it works. I will reply with results in a day or two. Commented Mar 22, 2018 at 13:02
-
1Add the code inside a try catch block to get more details about the error. Also if user is deleted from AD, it will not work. Commented Mar 22, 2018 at 13:56
-
Be assured that it is production code with all exception handling in place. If we pass an invalid user or other errors appear, very detailed info is written in log. Ridiculously, log from client contains no errors this user assignment. But also Author remains not assigned. Curiously, equal assignment of Editor works for client with equal code on very next line. We even tried to assign 'Created_x0020_By' to no avail also. Anyway, it is really tedious issue and we will update this thread as far as our communication with client proceeds. Commented Mar 22, 2018 at 17:25
-
As promised, I can give further feedback on this situation due to information from client. Exactly this code works very fine, gives no errors. Errors appear, if we intentionally break it by passing absent user to test error logging. And yet, after smooth code execution author in SharePoint is not updated! Commented Mar 29, 2018 at 9:13
Silly as it sounds, excellent code by @Gautam Sheth does not work. Please explore this answer for a weird hack necessary to update Author info in addition to valid code provided here. I refused to believe my eyes reading this. But yes, it works. All credits to original author.