1

I am building an ItemAdded Remote Event Receiver that is attached to a Document Library which contains a content type derived from the Document Set.

The Document Sets are configured to deploy sub-folders. Now when those sub folders are deployed SharePoint automatically also assigns the content type of the sub-folders as the derived Document Set. It would be nice if the sub folder's content type were just "Folder" but sadly they are not. So my goal is to reassign the content type of the sub-folder and do some other security manipulations. There is my problem.

In the processing of the ItemAdded event I need to examine the item being added so I determine if the item is the Document Set itself, a Document Set sub-folder or something else. Now since SharePoint assigns the sub-folder's content type the same as the parent a Document Set I am not able to compare content types to determine if it is a sub folder. I am also unable to use the FileSystemObjectType property because both the sub-folder and the parent content type are being returned as Folders. This leaves me unable to figure out how to isolate just the sub-folders. Below is my code. Hopefully someone has a better idea than what my approach is so far.

Thanks for reading!

public void ProcessOneWayEvent(SPRemoteEventProperties properties)
{
    using (ClientContext clientContext = TokenHelper.CreateRemoteEventReceiverClientContext(properties))
    {
        clientContext.Load(clientContext.Web);
        clientContext.Load(clientContext.Web.Lists);
        clientContext.Load(clientContext.Web.ContentTypes);
        clientContext.ExecuteQuery();

        List parentList = clientContext.Web.Lists.SingleOrDefault(l => l.Id == properties.ItemEventProperties.ListId);
        ListItem item = parentList.GetItemById(properties.ItemEventProperties.ListItemId);
        ContentType engineeringDocSetCT = clientContext.Web.ContentTypes.SingleOrDefault(c => c.Name == "Engineering Project");

        clientContext.Load(item);
        clientContext.Load(item.Folder);
        clientContext.Load(item.ContentType);
        clientContext.ExecuteQuery();

        switch (item.ContentType.Name)
        {
            case "Engineering Project":

                // This test does not work. Sub-folders and the Engineering Projct
                // Item come back as Folders
                if (item.FileSystemObjectType == FileSystemObjectType.Folder)
                {
                    Folder itemFolder = item.Folder;
                    string folderName = itemFolder.Name;
                }
                else
                {
                    string _projectName = properties.ItemEventProperties.AfterProperties["Title"].ToString();
                    string _projNum = properties.ItemEventProperties.AfterProperties["Project_x0020_Number"].ToString();
                    string _projRegion = properties.ItemEventProperties.AfterProperties["Project_x0020_Region"].ToString();
                    string _projSite = properties.ItemEventProperties.AfterProperties["Project_x0020_Site"].ToString();

                    item["Enginering_x0020_Project_x0020_Name"] = _projectName;
                    item["Project_x0020_Number"] = "New Project #";
                    item.Update();

                    clientContext.ExecuteQuery();
                }

                break;

            default:
                break;

        }
    }
}
}
  • FYI: The FileSystemObjectType evaluates as a folder because a Document Set is a folder. It's an inherited content type from the base folder content type with additional features. – RJ Cuthbertson Mar 25 '14 at 16:47
  • Yes apparently so. – ChiliYago Mar 25 '14 at 16:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.