Read sharepoint list items and display it inside a div in aspx page

So I have this sample aspx page with this design:
<div class="column1">Events</div>
<div class="column2">Details</div>
<div class="column3">Contact</div>
Now, I want to dynamically change the words (Events, Details, COntacts) depending on the content of my "Columns" sp list.
how can I do this?
----------------------- Sharepoint Newbie

Place the label controls in the div tags  like
<div class="column1">Eventslabel</div>
<div class="column2">Detailslabel</div>
<div class="column3">Contactlabel</div>
 public void ReadList() {  
  // Use using to make sure resources are released properly  
  using(SPSite oSite = new SPSite(pathToSite)) {  
    using(SPWeb oWeb = oSite.AllWebs[nameOfWeb]) {   
      // Alternately you can use oSite.RootWeb if you want to access the main site  
      SPList oList = oWeb.Lists[listName];  // The display name, ie. "Calendar"  
      foreach(SPListItem oItem in oList.Items) {  
        // Access each item in the list...  
       //Bind the values to label
        // etc....  

Similar Messages

  • How to read list item and display Title and on click hyperlink as value by javascript /jquery

    on newform.aspx just above the top of cancel button I want to put 1 hyperlink "Help"
    but I want to do this by script/jquery by reading my configuration list where 1 column is TITLE and other is- URL
    in TITLE column will write "Help" and in URL column  I will write
    http://portal1234/sites/sudha/MyHelppage.aspx
    so script should read Title and display Help--->1st part
    Script should read Value column and on click of help-(display link) the respective url should be open in new window.-->second part
    Please let me know reference code for adding anchor tag dynamically by reading from list
    I can see hyperlink near cancel button-
    $(document).ready(function(){
    var HelpLinkhtml ='<a href="#" text="Help">Help</a>';
    var position =$("input[value='Cancel']").parent("td").addClass('ms-separator').append(HelpLinkhtml);
    now for reading from list I am trying below script-
    $(document).ready(function() {
        GetHelpLinkFromConfigList();
    function GetHelpLinkFromConfigList()
     //The Web Service method we are calling, to read list items we use 'GetListItems'
     var method = "GetListItems";
     //The display name of the list we are reading data from
     var list = "configurationList";
     //We need to identify the fields we want to return. In this instance, we want the Title,Value fields
     //from the Configuration List. You can see here that we are using the internal field names.
     var fieldsToRead = "<ViewFields>"+"<FieldRef Name='Title' />"+"<FieldRef Name='Value' />"+"</ViewFields>";
     //comment
     var query = "<Query>" +
                            "<Where>" +
                                "<Neq>" +
                                    "<FieldRef Name='Title'/><Value Type='Text'>Help</Value>"
    +
                                "</Neq>" +
                            "</Where>" +
                            "<OrderBy>" +
                                "<FieldRef Name='Title'/>" +
                            "</OrderBy>" +
                        "</Query>";
     $().SPServices(
     operation: method,
        async: false,
        listName: list,
        CAMLViewFields: fieldsToRead,
        CAMLQuery: query,
        completefunc: function (xData, Status) {
        $(xData.responseXML).SPFilterNode("z:row").each(function() {
        var displayname = ($(this).attr("ows_Title"));
        var UrlValue = ($(this).attr("ows_Value")).split(",")[0];
        AddRowToSharepointTable(displayname,UrlValue)
    function AddRowToSharepointTable(displayname,UrlValue)
        $("#NDRTable").append("<tr align='Middle'>" +
                                    "<td><a href='" +UrlValue+ "'>+displayname+</a></td>"
    +
                                   "</tr>");
    <table id="NDRTable"></table>
    Thanks :)
    sudhanshu sharma Do good and cast it into river :)

    Hi,
    From your description, you want to add a help link(read data from other list) into new form page.
    The following code for your reference:
    <script src="http://code.jquery.com/jquery-1.10.2.min.js" type="text/javascript"></script>
    <script type="text/javascript">
    ExecuteOrDelayUntilScriptLoaded(AddHelpLink, "sp.js");
    function AddHelpLink() {
    var context = new SP.ClientContext.get_current();
    var list= context.get_web().get_lists().getByTitle("configurationList");
    var camlQuery= new SP.CamlQuery();
    camlQuery.set_viewXml("<View><Query><Where><Eq><FieldRef Name='Title'/><Value Type='Text'>Help</Value></Eq></Where></Query></View>");
    this.listItems = list.getItems(camlQuery);
    context.load(this.listItems,'Include(Title,URL)');
    context.executeQueryAsync(function(){
    var ListEnumerator = listItems.getEnumerator();
    while(ListEnumerator.moveNext())
    var currentItem = ListEnumerator.get_current();
    var title=currentItem.get_item("Title");
    var url=currentItem.get_item("URL").get_url();
    var HelpLinkhtml ='<a href="'+url+'">'+title+'</a>';
    $("input[value='Cancel']").parent("td").addClass('ms-separator').append(HelpLinkhtml);
    },function(sender,args){
    alert(args.get_message());
    </script>
    Result:
    Best Regards
    Dennis Guo
    TechNet Community Support

  • Query list items and display in client webpart..

    I am using the code below to display list items in clientwebpart but getting errors.Below is the code written in js file..What is wrong with the code??
    Error:javaScript runtime error: Unable to set property 'innerText' of undefined or null reference 
    'use strict';
    var context = SP.ClientContext.get_current();
    var user = context.get_web().get_currentUser();
    var web;
    var spHostUrl;
    var parentcontext;
    spHostUrl = decodeURIComponent(getQueryStringParameter('SPHostUrl'));
    parentcontext = new SP.AppContextSite(context, spHostUrl);
    web = parentcontext.get_web();
    var list = web.get_lists().getByTitle("ListsTask");
    var camlQuery = new SP.CamlQuery();
    camlQuery.set_viewXml("");
    this.listItems = list.getItems(camlQuery);
    context.load(listItems);
    context.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded),
        Function.createDelegate(this, this.onQueryFailed));
    // This code runs when the DOM is ready and creates a context object which is needed to use the SharePoint object model
    $(document).ready(function () {
        getUserName();
    // This function prepares, loads, and then executes a SharePoint query to get the current users information
    function getUserName() {
        context.load(user);
        context.executeQueryAsync(onGetUserNameSuccess, onGetUserNameFail);
    // This function is executed if the above call is successful
    // It replaces the contents of the 'message' element with the user name
    function onGetUserNameSuccess() {
        $('#message').text('Hello ' + user.get_title());
    // This function is executed if the above call fails
    function onGetUserNameFail(sender, args) {
        alert('Failed to get user name. Error:' + args.get_message());
    function getQueryStringParameter(urlParameterKey) {
        var params = document.URL.split('?')[1].split('&');
        var strParams = '';
        for (var i = 0; i < params.length; i = i + 1) {
            var singleParam = params[i].split('=');
            if (singleParam[0] == urlParameterKey)
                return decodeURIComponent(singleParam[1]);
        function onQuerySucceeded() {
            $("#results").empty();
            var listInfo = '';
            var listEnumerator = listItems.getEnumerator();
            listInfo += "<table><tr><th>Id</th><th>Title</th></tr>";
            while (listEnumerator.moveNext()) {
                var listItem = listEnumerator.get_current();
                listInfo += '<tr><td>' + listItem.get_item('ID') + '</td>'
                    + '<td>' + listItem.get_item('Title') + '</td>'
                    + '</tr>\n';
            listInfo += '</table>';
            $("#results").html(listInfo);
        function onQueryFailed(sender, args) {
            $("#results").empty();
            $("#results").text('Request failed. ' + args.get_message() +
                '\n' + args.get_stackTrace());

    HI,
    I have modified your code.
    'use strict';
    var context = SP.ClientContext.get_current();
    var user = context.get_web().get_currentUser();
    var web;
    var spHostUrl;
    var parentcontext;
    spHostUrl = decodeURIComponent(getQueryStringParameter('SPHostUrl'));
    parentcontext = new SP.AppContextSite(context, spHostUrl);
    web = parentcontext.get_web();
    // This code runs when the DOM is ready and creates a context object which is needed to use the SharePoint object model
    $(document).ready(function () {
        getUserName();
        getitems();
    // This function prepares, loads, and then executes a SharePoint query to get the current users information
    function getUserName() {
        context.load(user);
        context.executeQueryAsync(onGetUserNameSuccess, onGetUserNameFail);
    function getitems()
        var list = web.get_lists().getByTitle("ListsTask");
        var camlQuery = new SP.CamlQuery();
        camlQuery.set_viewXml("");
        this.listItems = list.getItems(camlQuery);
        context.load(listItems);
        context.executeQueryAsync(onQuerySucceeded1, onQueryFailed1);
    // This function is executed if the above call is successful
    // It replaces the contents of the 'message' element with the user name
    function onGetUserNameSuccess() {
        $('#message').text('Hello ' + user.get_title());
    // This function is executed if the above call fails
    function onGetUserNameFail(sender, args) {
        alert('Failed to get user name. Error:' + args.get_message());
    function getQueryStringParameter(urlParameterKey) {
        var params = document.URL.split('?')[1].split('&');
        var strParams = '';
        for (var i = 0; i < params.length; i = i + 1) {
            var singleParam = params[i].split('=');
            if (singleParam[0] == urlParameterKey)
                return decodeURIComponent(singleParam[1]);
        function onQuerySucceeded1() {
            $("#results").empty();
            var listInfo = '';
            var listEnumerator = listItems.getEnumerator();
            listInfo += "<table><tr><th>Id</th><th>Title</th></tr>";
            while (listEnumerator.moveNext()) {
                var listItem = listEnumerator.get_current();
                listInfo += '<tr><td>' + listItem.get_item('ID') + '</td>'
                    + '<td>' + listItem.get_item('Title') + '</td>'
                    + '</tr>\n';
            listInfo += '</table>';
            $("#results").html(listInfo);
        function onQueryFailed1(sender, args) {
            $("#results").empty();
            $("#results").text('Request failed. ' + args.get_message() +
                '\n' + args.get_stackTrace());
    But still not able to get list items, i m finding soultion.
    Thanks
    varinder

  • Click list item and display the image

    I have a database table:
    + One column includes names of the employee
    + Another includes the path of the file of corresponding employee's images
    I have added all the names into a JList
    Now, what I want to do is that: When I click on the item in the list, the image of the employee corresponding to the item will display in the frame.
    Could any of you help me?
    Any help will be appreciated.
    Thanks.

    Hi Sunitha,
    According to your description, my understanding is that you want to change the list title to an image.
    I recommend to add the code below to the list page:
    <script src="http://code.jquery.com/jquery-1.10.2.min.js" type="text/javascript"></script><script type="text/javascript">
    $(document).ready(function (){
    var s = "<img alt='SP' src='http://w2k81368:2116/SiteAssets/Test.jpg'>";
    var $t = $("#DeltaPlaceHolderPageTitleInTitleArea span span a");
    $t.html(s);
    </script>
    After that, the list title will change to the image and it will show allitems.aspx page when clicking the image.
    Thanks,
    Victoria
    Forum Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact
    [email protected]
    Victoria Xia
    TechNet Community Support

  • Detecting and displaying images inside SWF from same web page its embedded in

    Great forum and appreciate the great help I've been getting
    here. I am getting a bit more used to Flex now - the collection of
    controls is pretty amazing.
    I am trying to create an ImabeBrowse.SWF which when embedded
    on a web page, it would then automatically show thumbnails of all
    the images from that same page. Has anyone done anything like this
    in AS3?
    From documentation, it sounds like I would need to write some
    Javascript which would traverse the HTML's DOM to get all image
    URL's, and then pass these into the SWF?
    If one of you experts could share some code, that'd be
    greatly appreciated!!

    Asking for more.........
    Yes, I do agree there is no need to create an additional DAD when we want to call a procedure from infrastructure database (iasdb) because giving grant to public or portal_public schema is enough.
    But why is it that even after following the right way to create a DAD for HR schema in infrastucture database fails to call a procedure?
    The error which I get is:-
    Database Log In Failed
    TNS is unable to connect to destination. Invalid TNS address supplied or destination is not listening. This error can also occur because of underlying network transport problems.
    Verify that the TNS name in the connectstring entry of the DAD for this URL is valid and the database listener is running.
    The details for rajhr DAD
    Database Connectivity Information
    Database Username : HR
    Database Password : hr
    Databse Connection String : <blank>
    I have left database connection string blank as the infrastructure database is local.
    Is it that I cannot have two DAD for a local database eventhough they point to two different users?
    Med Vennlig Hilsen
    Rajesh

  • Open a SharePoint List item in Modal Pop up in SP 2013 fails after you filter or sort the list

    Sorry for the long post. This has been killing me. I had this script working perfectly fine in SharePoint 2010 (online) and basically i have a source custom list (list A) with a hyperlink column and a Destination List with say title and my name.
    Source List (list A) looks like this with these 2 columns
    Title    Test Link
    A         Link 1
    B         Link 2 
    C         Link 3
    Each of these links link to the actual list item in the destination list, so for example, link 1 is/sites/2013DevSite/Lists/Destination%20List/EditForm.aspx?ID=1
    So basically i want anytime the Link are clicked that point to another list's item to open in a modal dialog and the script below worked perfectly fine in SharePoint 2010 (online)
    <script language="javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" type="text/javascript"></script>
    <script language ="javascript" type="text/javascript">   
    jQuery(document).ready(function() {
    jQuery('a[href*="EditForm.aspx"]').each(function (i, e) {
    // Store the A tag's current href in a variable
    var currentHref = jQuery(e).attr('href');
    jQuery(e).attr({
    'href': 'javascript:void(0);', 
    // Use the stored href as argument for the ShowInModal functions parameter.
    'onclick': 'ShowInModal("' + currentHref + '");'
    function ShowInModal(href) {
    SP.UI.ModalDialog.showModalDialog({title: "Edit Item", url: href});    
    </script>
    All it does is find the href tags for that particular value Editform.aspx and the pop modal works in SP 2010 online. So the site page is designed in such a way there is a content editor web part with the reference to this javascript file and the sharepoint
    list is right beneath it and this worked perfectly opening in modal windows in SP 2010.
    Since migration to 2013, this is what exactly happens
    1.) when you come to the site page, the modal works,
    2.) If you filter or sort on say the Title or Test Link column in Source list (lets say you select the Value A), the script does not fire at all, if i hover over the hyperlink, the who hyperlink is shown and does not open the hyperlink in the modal pop up.
    - This is important because i want to be able to sort on a particular item...
    Could someone please let me know what am i doing wrong and why is this not working when i sort the list. Thanks for all the help.
    Once again i am trying to open a sharepoint list item in Sharepoint 2013 from another list using Jquery

    A ListItem has its own unique row id so in all likelihood, an insert with the same data will result in a new list entry. The Lists Web Service however, has an UpdateListItem method which will take an update request. [refer
    http://msdn.microsoft.com/en-us/library/office/websvclists.lists.updatelistitems(v=office.15).aspx ]
    There is another note in the conference (marked answered) to your List Item Update problem. Probably worth a try too. [refer
    http://social.msdn.microsoft.com/Forums/en-US/bee8f6c6-3259-4764-bafa-6689f5fd6ec9/how-to-update-an-existing-item-in-a-sharepoint-list-using-the-wss-adapter-for-biztalk?forum=biztalkgeneral ]
    Regards.

  • HT2531 Spotlight lists items and shows preview images.  BUT what about showing the location address of an item in my computer. Especially important if I've put the item in the wrong folder and what to locate it without multi-steps. iMac OS 10.5 was more u

    Spotlight lists items and shows preview images.  BUT what about showing the path/location address of an item in my computer.
    Especially important if I've put the item in the wrong folder and what to locate it without multi-steps. iMac OS X 10.5 was more useful.
    Old OSX Spotlight function automatically displayed path/location within the machine:  e.g. desktop/folder/sub-folder/item.
    Can I make Spotlight show the path?

    Press option-command and the path is displayed at the bottom of the little preview window.  Press command-return and the enclosing folder opens. 

  • How to create a multi column list item and select these values from a LOV

    Hi all,
    My requirements are:
    1) create an LOV which holds the productno, productname and productprice fields (this is working)
    2) at run time, select one record from LOV and populate the list/grid with this selected record values of productno, productname and productprice fields, so we are showing them on the form in the form of a table/grid (not working)
    3) be able to select multiple records from LOV and be able to populate the list item with multiple records (not working)
    4) have two more columns in the list/grid, for productquatity and total price (not wokring)
    Please help me.
    how can i create this grid or list in oracle
    whats the possible way of acheiving this in oracle

    If you use a list item to display multiple columns then you'll need to use a fixed-width font. You can achieve a similar look with proportional fonts by using a normal block and setting the fields' bevel to 'None'.
    Each column in the LOV has a Return Item property (under Column Mapping Properties). Set this to a :block.item reference for each column to bring the data back into those referenced fields.
    You can't select multiple records from an LOV. For this you will need to create your own form. Check the help for system.mouse_button_modifiers to see how to respond to Ctrl+click and Shift+click.
    To add columns just modify the LOV's record group's query.

  • How to fetch the Attched Filname of SharePoint List Item

    Hi All,
    Is there a way to fetch name of the file attached to the sharepoint list item ? Basically what we need is the file name which user has uploaded while submitting the new item, Later the same list item will get edited with another file attachment.
    We want to compare both these file names and set a Image status value which will be a dropdown. When a new item is created Status will be 'Submitted' after editing the same list item its status should become 'Resubmitted' only if attached file name is dfferent.
    We tried in SP designer 2010, but CurrentItem:Attachments is giving option either Yes or No. and from javascript we are able to retrieve filename attched but when stored it to another list column for comparison, the filename is stored as 1 which is a boolean
    value
    Please suggest us on how this can be done.
    Thanks,
    Raghu

    Hi Raghu,
    Did you the OOB Custom List? What't the error when you follow the steps from the above aritcle?
    I have ever tested a
    case to show attachment url in the Issue Tracking list, you can check if the following code could work for you.
    <xsl:element name="SharePoint:AttachmentsField">
    <xsl:attribute name="runat">server</xsl:attribute>
    <xsl:attribute name="FieldName">Attachments</xsl:attribute>
    <xsl:attribute name="Visible">true</xsl:attribute>
    <xsl:attribute name="ControlMode">Display</xsl:attribute>
    <xsl:attribute name="ItemId">
    <xsl:value-of select="$thisNode/@ID"/>
    </xsl:attribute>
    </xsl:element>
    Thanks
    Daniel Yang
    TechNet Community Support

  • Link to Sharepoint List Item

    I have a report that I built in SQL Report Builder 3.0 that pulls data from a SharePoint 2013 list. The fields are data, location, cost, department, and reference. The reference field is number that is input by the user on the SharePoint 2013 list. Is
    there a way for the reference field in the report to be a direct link back to open the SharePoint list item when it is clicked in the report?

    Hi,
    According to the description, I know you want to redirect to the SharePoint site by clicking on the value in the reference field in your report. Take the steps below to achieve this:
    1. Right-click reference field > Text box Properties in the designer surface.
    2. Click on Action page, check the option of Go to URL.
    3. In the Select URL box, type the URL of your SharePoint list.
    e.g. http://TestServer/toplevelsite/subsite/Lists/<Listname>/AllItems.aspx
    4. Click ok. Save and upload the report.
    This URL redirects to the SharePoint list page. If you want to redirect to the display form page of an item,
     use the code like:
    ="javascript:void(window.open('http://servername/sites/xx/Lists/listname/DispForm.aspx?ID=" & Fields!ID.Value & "&Title= "& Fields!Title.Value &"'))"
    ID and Title are used to identify the item which redirect to. You can change it according to the columns.                                                                                                                                                                                          
    Thanks.
    Tracy Cai
    TechNet Community Support

  • How to insert sharepoint list item attachment to sql server db programatically

    Hi,
    I need to insert sharepoint list item attachments to sql server db programatically. Could some one suggest some approach and if any one work on it please provide the code. Thanks in advance

    hi,
    you can do it using powershell. Use the below script to loop through all the items attachments inside list.
    $web = $site.RootWeb<br />
    $Lists = $Web.Lists[$ListName]
    $Library = $web.Lists[$LibName]
    foreach($listItem in $Lists.Items)
    if($listItem.Attachments.Count -gt 0)
    Write-Host "**************************************************"
    Write-Host $listItem.Attachments.Count"Attachment(s) available in the ListItem:" $listItem.Title
    Write-Host "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
    $i=0
    foreach($attachment in $listItem.Attachments)<br />
    $i++
    Write-Host $i".Attachment Name:" $listItem.Attachments.UrlPrefix$attachment
    $file = $web.GetFile($listItem.Attachments.UrlPrefix+$attachment)
    Write-Host "Adding Files to Library:"$Library.Title
    $bytes = $file.OpenBinary()
    Write-Host "Successfully Added"<br /> Write-Host "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
    Write-Host "**************************************************"
    And use the below script to insert into SQL.
    #Connect to DB
    $DB = “server=MyInstanceName;integrated security=sspi;database=Bob”
    $conn = new-object System.Data.SqlClient.SqlConnection($DB)
    #Build the command and parameters
    $cmd = New-Object System.Data.SQLClient.SQLCommand
    $cmd.CommandType = [System.Data.CommandType]‘StoredProcedure‘
    $cmd.Parameters.Add(“@Col1″, [System.Data.SqlDbType]‘VarBinary‘)
    $cmd.Parameters[“@Col1″].Size = -1
    $cmd.Parameters[“@Col1″].Value = $bytes
    $sql = "INSERT INTO <table> (Col1) VALUES " + $cmd.Parameters[“@Col1″]
    #Execute the command
    $conn.Open()
    $cmd.ExecuteNonQuery()
    P.S. There may be some syntax error you have to make it work but the concept is right.
    Whenever you see a reply and if you think is helpful,Vote As Helpful! And whenever you see a reply being an answer to the question of the thread, click Mark As Answer

  • CAML Query to Sort SharePoint list items based on Modified date

    hi ,
    can we sort sharePoint list items based on 'Modified' column, the sorting should be done up to milliseconds level.
    currently i am using CAML query as below
    <OrderBy><FieldRef Name='Modified' Type='DateTime' IncludeTimeValue='TRUE' Ascending='False'/></OrderBy>but its not considering milliseconds while sorting.
    Thanks and Regards,
    venkatesh.

    Veda, thanks but I'm not really a hardcore C# coder.
    We found more elegant solution was to create a List View which returns all records that should be deleted, based on our own custom deletion criteria, and then create an very simple SSIS Package in Visual Studio using the
    Sharepoint Connectors for SSIS to delete all Sharepoint List Items returned from that List View. The Sharepoint Destination Connector has a delete operation.
    This worked for us and didn't require any coding.

  • Unable to Read Calendar List Items through CAML

    Hi All,
    * I have created two columns in calendar one Year and other Month.When new event is added in calendar through (Item Added) event receiver I am setting the values to this columns as Name of Month to(February) and Year as(2014)  .So that I can fetch the
    data easily based on month and year
    * Through this Columns Secondly when I try to fetch the data to count number of items of particular month and year using caml query I am getting error as below .
    "Error:One or more field types are not installed properly. Go to the list settings page to delete these fields."
    *My below caml code is working fine if i applied to custom list,But not to calendar.Can any one help me for what reason I am unable to fetch data
    Code
     string year="2014";
     string month="February";
     SPSite mysite = SPContext.Current.Site;
     SPWeb myweb = mysite.OpenWeb();
    SPList mylist = myweb.Lists["Calendar"];
     SPQuery myquery = new SPQuery();
      myquery.Query = @"<Where>
                                          <And>
                                           <Eq>
                                             <FieldRef Name='Year'/>
                                             <Value Type='Text'>" + year + @"</Value>
                                          </Eq>
                                          <Eq>
                                             <FieldRef Name='Month' />
                                             <Value Type='Text'>" + month + @"</Value>
                                          </Eq>
                                         </And>
                                      </Where>";
     SPListItemCollection totaltiems = mylist.GetItems(myquery);
      Label1.Text= "Total Number of Items is "+" "+totaltiems.Count.ToString();
    Thanks, Quality Communication Provides Quality Work. http://siddiq-sharepoint2010.blogspot.in/ Siddiqali Mohammad .

    Hi,
    According to your post, my understanding is that you got an error when read calendar list items using CAML.
    I created two single line of text columns in the Calendar( Year and Month), then add items in the Calendar to check with your code. The CAML query worked well as below.
    string year = "2014";
    string month = "February";
    using (SPSite oSiteCollection = new SPSite("Your site URL"))
    using (SPWeb myweb = oSiteCollection.OpenWeb())
    SPList mylist = myweb.Lists["Calendar"];
    SPQuery myquery = new SPQuery();
    myquery.Query = @"<Where> <And> <Eq> <FieldRef Name='Year'/> <Value Type='text'>" + year
    + "</Value></Eq><Eq>+ "
    + " <FieldRef Name='Month' />+ "
    + " <Value Type='text'>" + month + "</Value>+ "
    + " </Eq> </And></Where>";
    SPListItemCollection totaltiems = mylist.GetItems(myquery);
    Console.WriteLine( "Total Number of Items is " + " " + totaltiems.Count.ToString());
    Console.ReadLine();
    Which type of the two columns in your Calendar? Were they text type?
    Are you sure the field name(<FieldRef Name='Year'/>,
    <FieldRef Name='Month' />) is same as internal name?
    We should only use internal name while refrencing columns in CAML query. If you have space In you column , replace it with "_x0020_", such as
    News_x0020_Category. 
    Thanks & Regards,
    Jason 
    Jason Guo
    TechNet Community Support

  • Report workload by calculating how many versions of SharePoint list items created in a certain time period

    I have a total of 66 SharePoint 2010 lists - yes, 66! - each lists contains between 1500 and 3200 list items.  My employees update these various list items throughout their workday.  Each update to a list item creates a new version of the list
    item.  On average each list item will have anywhere from 5 to 10 versions before it is done.  I need to create a report that tells me how many list items they've updated in a certain time frame.  I have come close but still cannot arrive at
    the data I'm looking for. 
    This is what I have so far:
    I've created a report using SQL Report Builder 2008 v3 where I've filtered it to show only items MODIFIED between, for example, Feb1 and Feb28.  Of those records, I want the report to tell me how many versions were created during that time
    frame.  The result is one list item with 5 total versions.  Versions 1.0, 2.0, & 3.0 were created on 12/12/14.  The last two versions, 4.0 and 5.0, were created on 2/24/15.  Therefore, the answer I'm looking for is 2 because they
    created 2 versions between Feb1 and Feb28.
    However I get the following results using these queries:
    If I do a =Sum(Fields!owshiddenversion.Value) in the expression field I get the total versions which is 5
    If I do a =Count(Fields!owshiddenversion.Value) in the expression field I get the instance which is 1
    Is there a way to count ONLY the number of versions created in a time period?  Is there another hidden field in SharePoint that I can use in the expression that will give me results I'm looking for?

    Hi Rafael70,
    Per my understanding that you have already get all the need fields and informaiton of the updated version of list items and now you want to calculate how many versions of SharePoint list items created in a certain time period, you can't get desired result
    using sum and count function, right?
    I have tried to tested on my local environment but because I am not clear what is value in the field "owshiddenversion", I assumed you have two datatype parameters (StartDate and EndDate) to help filter the report in a certain time period.
    Generally, if you have add the filter correctly, it will filter the correct number's updated version in this time period, I would like you to provide details information as below to help better analysis the requirements:
    Could you please provide sample data of the table.
    Please provide snapshot of the report structure you have currently designed.
    Please try to provide all the expression you have used.
    If you still have any problem, please feel free to ask.
    Regards,
    Vicky Liu
    Vicky Liu
    TechNet Community Support

  • Syntax Error with JSON.Parse method to parse SharePoint List Items

    Hi All,
    I want to get SharePoint List data and bind that retrived data to the JQuery Grid Control.
    For this I used SPServices to get the SharePoint List data in SOAP Envelope. Now I need to parse the soap envelope and store the retrieved items in array to pass it to the Grid Control.
    While using the JSON.Parse(resporseText) method, Iam consistenly getting an Syntax Error!
    Could anyone help me with this ?
    Please find the SOAP Envelope I received from SP List as below:
    "<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><GetListItemsResponse xmlns="http://schemas.microsoft.com/sharepoint/soap/"><GetListItemsResult><listitems xmlns:s='uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882'
    xmlns:dt='uuid:C2F41010-65B3-11d1-A29F-00AA00C14882'
    xmlns:rs='urn:schemas-microsoft-com:rowset'
    xmlns:z='#RowsetSchema'>
    <rs:data ItemCount="2">
    <z:row ows_OBNumber='112211.000000000' ows_Project_x0020_Name='Project 1' ows_MetaInfo='11;#' ows__ModerationStatus='0' ows__Level='1' ows_Title='Project 1' ows_ID='11' ows_UniqueId='11;#{FBBCBCF9-666D-42F9-92D7-67188C51BC9B}' ows_owshiddenversion='1' ows_FSObjType='11;#0' ows_Created='2015-01-12 10:25:06' ows_PermMask='0x7fffffffffffffff' ows_Modified='2015-01-12 10:25:06' ows_FileRef='11;#sites/Lists/Projects/11_.000' />
    <z:row ows_OBNumber='1122343.00000000' ows_Project_x0020_Name='Project 2 ' ows_MetaInfo='12;#' ows__ModerationStatus='0' ows__Level='1' ows_Title='Project 2' ows_ID='12' ows_UniqueId='12;#{0D772B76-68E4-4769-B6FF-6A269F9C7ABD}' ows_owshiddenversion='1' ows_FSObjType='12;#0' ows_Created='2015-01-12 10:33:48' ows_PermMask='0x7fffffffffffffff' ows_Modified='2015-01-12 10:33:48' ows_FileRef='12;#sites/Lists/Projects/12_.000' />
    </rs:data>
    </listitems></GetListItemsResult></GetListItemsResponse></soap:Body></soap:Envelope>"
    Any help on this will be greatly appreciated.
    Thanks In Advance.!

    Hi,
    According to your description, there is an issue when parsing result from the data retrieved using SPServices.
    By default, SPServices returns data as XML format, however, the JSON.parse() method “Throws a SyntaxError exception if the string to parse is not valid JSON”:
    https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse
    To extract the data needed from the response, you can either take the demo below for as a reference:
    http://spservices.codeplex.com/wikipage?title=GetListItems
    Or use the jQuery.parseXML() function:
    http://api.jquery.com/jquery.parsexml/
    Best regards
    Patrick Liang
    TechNet Community Support

Maybe you are looking for