Update properties of document
-
09-10-2020 - |
Question
I'm trying to update properties of documents in my SharePoint site using C# code.
This is the code I'm using to get to the folder I need:
public SPArchiveBDI(string sharepointsite, string documentLibraryName)
{
_sharePointSite = sharepointsite;
_documentLibraryName = documentLibraryName;
context = new ClientContext(SharePointSite);
list = context.Web.Lists.GetByTitle(DocumentLibraryName);
context.Load(list);
context.Load(list.RootFolder);
context.ExecuteQuery();
root = list.RootFolder;
context.Load(root);
context.ExecuteQuery();
customerFolder = root.Folders.GetByUrl("לקוחות");
context.Load(customerFolder);
context.ExecuteQuery();
bDIFolder = customerFolder.Folders.GetByUrl("BDI");
context.Load(bDIFolder);
context.ExecuteQuery();
}
This code works fine.
My problem is with the code I'm using to update two properties in documents in that folder.
public void ChangeFileInBDI(string name, int WFID, int entityID)
{
File doc = bDIFolder.Files.GetByUrl(name);
context.Load(doc);
context.ExecuteQuery();
ListItem lst = doc.ListItemAllFields;
lst["מספר תהליך"] = WFID;
lst["EntityId"] = entityID;
lst.Update();
context.ExecuteQuery();
}
The name is the name of the document in the folder and the code actually finds it.
The code falls in the last row, where it says context.ExecuteQuery().
The error message says:
A first chance exception of type 'Microsoft.SharePoint.Client.ServerException' occurred in Microsoft.SharePoint.Client.Runtime.dll
Additional information: Column 'מספר תהליך' does not exists. Someone else may have deleted it. /TenDocuments
If there is a handler for this exception, the program may be safely continued.
My folder and document contain these properties and I have no idea why my code falls.
Can someone tell me where my problem is?
Thank you in advance!
La solution
My problem was the names on the columns.
Instead of naming them like I see them on the SharePoint site, I should have named them as the encoded name they have: "_x05de__x05e4__x05e8.....".
Now it works