The following code can be used to check the folder exists in Sharepoint Site:
public static SPFolder CheckFolderExists(SPList targetList, string folderUrl)
{
SPFolder folder = null;
if (string.IsNullOrEmpty(folderUrl))
return targetList.RootFolder;
SPFolderCollection col = targetList.ParentWeb.Folders;
foreach (SPFolder item in col)
{
foreach (SPFolder fol1 in item.SubFolders)
{
foreach (SPFolder fol2 in fol1.SubFolders)
{
if (fol2.Name.ToLower() == folderUrl.ToLower())
{
folder = fol2;
return folder;
}
}
}
}
return folder;
}
No comments:
Post a Comment