I have a loop that is looping through a document library like in the example below.
foreach (SPListItem item in DocumentLibrary)
{
}
How do I tell if the SPListItem is a document or a folder?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The Folder property of the list item will be
nullif the item is not a folder, so you can write:In the same way, the File property of the item will be
nullif the item is not a document. However, the documentation advises against using this property in that case:An alternate way is to check the BaseType property of the list: