1

I have a navigation web part which displays the subsites as tiles which has the name of the subsite and last modified date information. These subsites can have multiple document libraries, lists(includes calendar and subsites. Is there a way to find using JSOM which element was modified within that subsite?

1 Answer 1

0

I ended up creating a service in CSOM instead of JSOM. I used SPSiteDataQuery to query all document libraries inside a site to get the last modified file. I found this blog very useful to understand what SPSiteDataQuery does.

 public DataTable LastModifiedDocument(string siteUrl)
    {
using (SPSite site = new SPSite(siteUrl))
 {
  if (site != null)
  {
   using (SPWeb web = site.OpenWeb())
   {
     SPSiteDataQuery query = new SPSiteDataQuery();

     // Query all Web sites in this site collection.
      query.Webs = "<Webs Scope='Recursive'>";

      //Query all document libraries inside the site collection recursively.
        query.Lists = "<Lists ServerTemplate='101' />";

        // Get the properties of the document.
        query.ViewFields = "<FieldRef Name='Title' Nullable='TRUE' />" +
                           "<FieldRef Name='Created' Nullable='TRUE' />" +
                           "<FieldRef Name='Created_x0020_By' Nullable='TRUE' />" +
                           "<FieldRef Name='ContentType' Nullable='TRUE' />" +
                           "<FieldRef Name='FileRef' Nullable='TRUE' />" +
                           "<FieldRef Name='FileLeafRef' Nullable='TRUE' />" +
                           "<FieldRef Name='Modified' Nullable='TRUE' />" +
                           "<FieldRef Name='Modified_x0020_By' Nullable='TRUE' />";

         // Set the sort order based on modified date.
         query.Query = "<Where><Eq>" +
                       "<FieldRef Name='ContentType' />" +
                       "<Value Type='Text'>Document</Value></Eq>" +
                        "</Where>" +
                        "<OrderBy>" +
                        "<FieldRef Name='Modified' Ascending='FALSE' />" +
                        "</OrderBy>";
         //I need only one document which was modified recently in that site.
         query.RowLimit = 1;

         DataTable dt = web.GetSiteData(query);
         //GetSiteData returns a data table.

          web.Close();
          }

 site.Close();
 }
}
return dt;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.