Determine If There Are Files And Folders In SharePoint Document Library

This example shows you how to determine whether there are files or folders in a SharePoint asset. This is an asset existence method and can be used to prevent the overriding of other content.
[csharp]

public static bool FolderContainsAssets(SPFolder folder, string fileName)
{
        foreach (SPFile file in folder.Files)
        {
                if (string.Compare(fileName, file1.Name, true) == 0)
                {
                        return true;
                }
        }
        return false;
}

public static bool FolderContainsOtherFolders(SPFolder folder, string folderName)
{
        foreach (SPFolder folder in folder.SubFolders)
        {
                if (string.Compare(folderName, folder1.Name, true) == 0)
                {
                        return true;
                }
        }
        return false;
}

[/csharp]

Share

Leave a Reply

Your email address will not be published. Required fields are marked *