Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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">
   <td>
<b>View <a href="../{@DocumentLibrary}/{@Application}/">Documentation</a></b>
   </td>
</xsl:when>
share|improve this question
    
The xsl count function counts the number of xml nodes in the given path. See reference: msdn.microsoft.com/en-us/library/ms256103.aspx. 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
add comment

1 Answer

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;
            break;
        }
    }
}
share|improve this answer
add comment

Your Answer

 
discard

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.