I'm trying to modify two properties I have in several documents in my SharePoint library.
This is the code I use to get into the library:
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 and I have no trouble using it.
This is the code I use to modify the properties of the document:
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["_x05de__x05e1__x05e4__x05e8__x0020__x05ea__x05d4__x05dc__x05d9__x05da_"] = WFID;
lst["_x05d6__x05d9__x05d4__x05d5__x05d9__x0020__x05d9__x05d9__x05e9__x05d5__x05ea_"] = entityID;
lst.Update();
context.ExecuteQuery();
}
In the last line of the code the program falls and the error message I got says:
Additional information: Access denied. You do not have permission to perform these actions or to use that resource.
I looked it up and decided to use "RunWithElevatedPrivileges".
This is the code I tried to run:
public void ChangeFileInBDI(string name, int WFID, int entityID)
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(context.Site.Id))
{
File doc = bDIFolder.Files.GetByUrl(name);
context.Load(doc);
context.ExecuteQuery();
ListItem lst = doc.ListItemAllFields;
lst["_x05de__x05e1__x05e4__x05e8__x0020__x05ea__x05d4__x05dc__x05d9__x05da_"] = WFID;
lst["_x05d6__x05d9__x05d4__x05d5__x05d9__x0020__x05d9__x05d9__x05e9__x05d5__x05ea_"] = entityID;
lst.Update();
context.ExecuteQuery();
}
});
}
When I try to that code it falls in the line "using (SPSite site = new SPSite(context.Site.Id))".
The error message says that the property Id has not been initialized.
My context object is global and usually I have no problem using it.
What am I doing wrong?
Thank you in advance!