1

I'm new to SharePoint and have a general question regarding list comparison. Currently, there is a user generated list that is constantly changing, and I wanted to gather quantitative data regarding the changes. Each day, I come in at 8:00 and then leave again at 5:00. I want to know what/how many items are in that list at 8:00 vs. 5:00 and then be able to review the results. For example, the list contains current projects that I need to finish. If there are 20 when I come in at 8:00, and 3 when I leave, I want to be able to view data that I completed 85% of the projects and 17/20. Is this possible?

*Note, currently, I do not have SharePoint Designer or access to the server. Assuming access is needed and I can get it, what would be the best way to approach this?

Jonny
  • 619
  • 4
  • 12
  • 31

2 Answers2

1

Timerjob might be a decent option. It's a little bit of coding that would just hit the list query all items and count and then ping an E-Mail to someone or drop the figure it returns somewhere in SharePoint.

In addition i would have a read around http://www.andrewconnell.com/blog/articles/CreatingCustomSharePointTimerJobs.aspx blog for information as to how to code a timer job.

To actually get what you are needing I will talk you through what you need to do but won't give you the code as you should really attempt first before asking.

Get a spsite object.(This should contain the web containing your list) Get the web object containing your list. Get the list

SPList countLIst = <yourWeb>.lists["<listname or GUID>"]

Get the list count

int numberOfItems = countList.items.count

somehow display or save numberOfItems

Remember SPContext.current.site will not work within timer jobs due to their context.

Hope this extension fulfills your request

Cheers Truez

Truezplaya
  • 1,315
  • 1
  • 13
  • 26
  • Since the OP mentioned that he doesn't have access to the server, we can assume that a solution that requires the Sharepoint.dll library (or installing a solution that includes a timer job) like you suggest, won't really be his best choice. – Patrick Pitre Jun 30 '12 at 04:57
1

There's really no built-in way to do this. But with all things SharePoint, there are multiple ways to accomplish things. Since you don't have access to SP Designer, or the server itself, probably the path of least resistance would be to use the SP Web Services to query the list (say, at 8AM) and get a count of items, store (persist) the item-count somewhere, then query the list again (5PM), and check it against the initial day's count, and give you a total.

You can access List data via the SP Web Services at http://server_name/_vti_bin/Lists.asmx. Use something like the code below to get the list count. You can persist the stored value anywhere - text file, local storage, memory..

Note, you need to add a Web Service reference to your project. In the code below, this is named sp2010, but obviously you can name your whatever you want. The variable listItemCount will hold your list count. Much of the rest of the code should be self-explanatory.

            sp2010.Lists spList = new sp2010.Lists() { Credentials = new NetworkCredential("username", "password") };
            string listName = "YourListName"; 
            string listItemCount = string.Empty;

            XmlNode listXML = spList.GetListItems(listName, null, null, null, null, null, null);

            XmlDataDocument innerXml = new XmlDataDocument();
            innerXml.LoadXml(listXML.InnerXml);
            XmlNodeList rows = innerXml.GetElementsByTagName("rs:data");

            foreach (XmlNode attribute in rows)
                {
                    // listItemCount holds the count of your list
                    listItemCount = attribute.Attributes["ItemCount"].Value;
                }
Patrick Pitre
  • 843
  • 4
  • 6
  • Thanks! I appreciate an answer that doesn't require server authentication. I'll look into this as well in the next week. – Jonny Jul 02 '12 at 12:40
  • The only authentication you need is your regular credentials you need to view the list - nothing more. And since it hits the Web Services, you don't need anything installed on the local server. – Patrick Pitre Jul 02 '12 at 20:27
  • What language is this code? C/Java? and where do I run the program from? – Jonny Jul 03 '12 at 18:11
  • 1
    This is C# code. You can run it from any type of .Net program: a Console application, a WinForms app, an ASP.NET/MVC web application. After you create a program, take the URL I have you in the answer, right click Service References, click Add Service Reference, and add the URL. Give it a name (I named mine sp2010). Once it's added to the project, use the code above to connect to the SP site, and get the list count. – Patrick Pitre Jul 03 '12 at 19:01