locked
Getting the count of items in a folder to be used in an info path form RRS feed

  • Question

  • Hi,

      I have a field in the info path form that represents the count of this form in the doc/form libarary that it is created in. I have some folders in this library and I wanted to set this field to the count of this form in the folder that it’s created in instead of the whole library. I want to know how to get the count of items in a given folder name using web services or using infopath rules and how to make sure that 2 forms initiated at the same time won’t have the same value.

    Thanks in advance.


    Wednesday, August 24, 2011 10:44 AM

Answers

All replies

  • Hi Marwa,

     

    I didn't find proper web services to achieve this. But I find a reusable method that could return the item count from a specified folder. You can refer to:

     

    http://www.sharepointsecurity.com/general/returning-sharepoint-folder-item-count-in-c/

     

    Thanks,

    Pengyu Zhao

    • Marked as answer by Wayne Fan Friday, September 2, 2011 2:29 AM
    Monday, August 29, 2011 9:22 AM
  • Hi,

    At first thanks for your reply.

    Second, I modified the view of the current library to show the count of items and it shows the count correctly in each folder so I wanted to know can I access this value in infopath or In getlistitems web service can I modify the query to get count of items instead of certain fields?

    I wrote the below code to access folders in the library as per the following links http://blogs.msdn.com/b/karthick/archive/2006/03/27/562245.aspx

    http://sharepointmagazine.net/articles/writing-caml-queries-for-retrieving-list-items-from-a-sharepoint-list

     but I still get the count of items in root folder:

    XmlDocument camlDocument = new XmlDocument();
    XmlNode queryNode = camlDocument.CreateElement("Query");
    queryNode.InnerXml = "";
    XmlNode viewFieldsNode = camlDocument.CreateElement("ViewFields");
    viewFieldsNode.InnerXml = "<FieldRef Name='Name'/>";
    XmlNode queryOptionsNode = camlDocument.CreateElement("QueryOptions");
    queryOptionsNode.InnerXml = "<ViewAttributes Scope=\"Recursive\" /><Folder>Library/FolderName</Folder>";
    XmlNode testitems = listService.GetListItems("Library", null, null,
    null, null,QueryOptions, null);
    
    XmlNamespaceManager nm = new XmlNamespaceManager(testitems.OwnerDocument.NameTable);
    
    nm.AddNamespace("z", "#RowsetSchema");
    
    XmlNodeList zRows = testitems.SelectNodes("//z:row", nm);

    I tried to pass null parameters for query and view fields and tried using the ones in the code but no use.

    Any help would be appreciated.

    Thanks


    Sunday, September 11, 2011 8:36 AM
  • Hi,

    Could anyone get the count of items in a folder without using SP object model as I don't have the option to deploy code on server?

    Thanks.

    Monday, September 12, 2011 2:33 PM