Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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.

share|improve this question
    
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. –  user15798 Mar 21 '13 at 13:06
add comment

1 Answer

up vote 6 down vote accepted

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.

share|improve this answer
    
Thanks, I would like to recommend using of "FileRef" (folder directory) instead of "FileLeafRef" (folder name). –  Warlock Mar 4 '13 at 18:58
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.