SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have created a custom web part that displays information from a list of applications. I have created a sepearte document library that contains a folder for each application. I created a 'View Documentation' link that will link to the correct folder for the application. However I would like this link only to display when the folder contains a document. Although my link works, the count function does not. Please help

<xsl:when test="  count(../{@DocumentLibrary}/{@Application}/) != 0">
<b>View <a href="../{@DocumentLibrary}/{@Application}/">Documentation</a></b>
share|improve this question
The xsl count function counts the number of xml nodes in the given path. See reference: If you can't include the documents themselves in the xml then you have have to check this with code. – Ryan Erickson Mar 15 '13 at 19:05
Ryan, Thank you for your response. I have discovered that the count function only works with nodes. I don't think that it is plausible to include the documents themselves. Would you have an idea of how to check this with code? – Shelly Miner Mar 15 '13 at 20:32

Here is a code example to check if a folder contains any documents:

using (SPWeb web = SPContext.Current.Web)
    SPList oList = web.Lists["ListName"];
    SPListItemCollection collListItems = null;
    foreach (SPFolder subFolder in oList.RootFolder.SubFolders)
        if (subFolder.Name.ToLower() == FolderName.ToLower().Trim())
            SPQuery oQuery = new SPQuery();
            oQuery.Query = "<OrderBy><FieldRef Name=’Modified’ Ascending=’False’ /></OrderBy>";
            oQuery.Folder = subFolder;
            collListItems = oList.GetItems(oQuery);
            int hasDocs = colListItems.Count() > 0;
share|improve this answer

Your Answer


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.