11

In an application I'm working on, I'm interacting with SharePoint (2010) via the .NET Client-Side Object Model, and am trying to account for a large number of possible configurations of document libraries.

In the instance that a document library has content approval enabled, if I create a new Folder object, the approval status applies to this ListItem as well:

Newly Created Folder

How can I get a reference to the ListItem that is the newly created Folder object?

I need to set this value to SPModerationStatusType.Approved programmatically when I create a new folder, but can't find a way to modify the fields of the ListItem given that I only have a Folder object.

I want to get a ListItem object so I can do something like this:

Working With Content Approval / Moderation In CSOM

Edit:

For SharePoint 2013, they've apparently taken this into consideration and have added a Folder.ListItemAllFields property which would be exactly what I need here, but this property is unavailable to the 2010 CSOM.

1
  • can you please put the entire code.. as for me the query is showing null. I want to edit the _approval status as approved for folders/ subfolder recursivly.can you please help. Commented Mar 21, 2013 at 13:06

1 Answer 1

10

I solved this by using a CamlQuery directly after creation to return folders with the same name as a ListItemCollection:

SP.CamlQuery query = new SP.CamlQuery(); query.ViewXml = "<View Scope='RecursiveAll'>" + "<Query>" + "<Where>" + "<And>" + "<Eq>" + "<FieldRef Name='ContentType'/>" + "<Value Type='Text'>Folder</Value>" + "</Eq>" + "<Eq>" + "<FieldRef Name='FileLeafRef'/>" + "<Value Type='Text'>" + subFolderName + "</Value>" + "</Eq>" + "</And>" + "</Where>" + "</Query>" + "</View>"; SP.ListItemCollection items = list.GetItems(query); clientContext.Load(items); clientContext.ExecuteQuery(); 

With a little validation of the item I can set the property as I need.

1
  • Thanks, I would like to recommend using of "FileRef" (folder directory) instead of "FileLeafRef" (folder name). Commented Mar 4, 2013 at 18:58

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.