Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. SharePoint
  4. Sharepoint CAML query for SPQuery.GetItems() [modified]

Sharepoint CAML query for SPQuery.GetItems() [modified]

Scheduled Pinned Locked Moved SharePoint
sharepointdatabasecomhelp
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    gottimukkala
    wrote on last edited by
    #1

    Hi We have discussions webpart customized to us and I want to get the number of discussoins from a particular user. My problem is when I pass the First Name and Last Name of the user (which is the displayname on the ffront end )in my query then I would able to get the correct count but if I pass the username then I am not able to the correct count from that user. Is there a way that I can say that get by username. Please have a look at my SPQuery code: SPQuery query = new SPQuery(); SPList splist = spWeb.Lists["Forum"]; query.Query = "<Where><Or><Eq><FieldRef Name='Author'/>" + "<Value Type='User'>" + spUsrDisplayName + "</Value>" + "</Eq><Eq><FieldRef Name='Editor'/>" + "<Value Type='User'>" + spUsrDisplayName + "</Value>" + "</Eq></Or></Where>"; query.ViewFields = ""; SPListItemCollection spListColl = splist.GetItems(query); int discussionsCount = spListColl.Count; Can any one give me any idea please. Thanks, Regards, Aruna

    -- http://ashakthi.blogspot.com http://kids-articles.blogspot.com

    modified on Wednesday, November 25, 2009 4:20 AM

    M E 2 Replies Last reply
    0
    • G gottimukkala

      Hi We have discussions webpart customized to us and I want to get the number of discussoins from a particular user. My problem is when I pass the First Name and Last Name of the user (which is the displayname on the ffront end )in my query then I would able to get the correct count but if I pass the username then I am not able to the correct count from that user. Is there a way that I can say that get by username. Please have a look at my SPQuery code: SPQuery query = new SPQuery(); SPList splist = spWeb.Lists["Forum"]; query.Query = "<Where><Or><Eq><FieldRef Name='Author'/>" + "<Value Type='User'>" + spUsrDisplayName + "</Value>" + "</Eq><Eq><FieldRef Name='Editor'/>" + "<Value Type='User'>" + spUsrDisplayName + "</Value>" + "</Eq></Or></Where>"; query.ViewFields = ""; SPListItemCollection spListColl = splist.GetItems(query); int discussionsCount = spListColl.Count; Can any one give me any idea please. Thanks, Regards, Aruna

      -- http://ashakthi.blogspot.com http://kids-articles.blogspot.com

      modified on Wednesday, November 25, 2009 4:20 AM

      M Offline
      M Offline
      Member 3836567
      wrote on last edited by
      #2

      User the following code to get username. The username is usually in "domain\\username" format. SPWeb oWeb = SPContext.Current.Web; SPUser sUser = oWeb.CurrentUser; string sUserName = sUser.LoginName Use the following method to remove extra slashes. public string getUserName(string strLogin) { string str = ""; // Parse the string to check if domain name is present. int idx = strLogin.IndexOf('\\'); if (idx == -1) { idx = strLogin.IndexOf('@'); } string strDomain; string strName; if (idx != -1) { strDomain = strLogin.Substring(0, idx); strName = strLogin.Substring(idx + 1); } else { strDomain = Environment.MachineName; strName = strLogin; } return strName; } } Check if it is working for you with or with out removing extra slashes. If you are looking for help with SPQuery let me know. -Susheel Dakoju

      E 1 Reply Last reply
      0
      • G gottimukkala

        Hi We have discussions webpart customized to us and I want to get the number of discussoins from a particular user. My problem is when I pass the First Name and Last Name of the user (which is the displayname on the ffront end )in my query then I would able to get the correct count but if I pass the username then I am not able to the correct count from that user. Is there a way that I can say that get by username. Please have a look at my SPQuery code: SPQuery query = new SPQuery(); SPList splist = spWeb.Lists["Forum"]; query.Query = "<Where><Or><Eq><FieldRef Name='Author'/>" + "<Value Type='User'>" + spUsrDisplayName + "</Value>" + "</Eq><Eq><FieldRef Name='Editor'/>" + "<Value Type='User'>" + spUsrDisplayName + "</Value>" + "</Eq></Or></Where>"; query.ViewFields = ""; SPListItemCollection spListColl = splist.GetItems(query); int discussionsCount = spListColl.Count; Can any one give me any idea please. Thanks, Regards, Aruna

        -- http://ashakthi.blogspot.com http://kids-articles.blogspot.com

        modified on Wednesday, November 25, 2009 4:20 AM

        E Offline
        E Offline
        elizas
        wrote on last edited by
        #3

        For instance, let us take a State List which holds all the states of India. States are grouped under different zones i.e. North, South, East & West. If I need to retrieve all the States for North zone then my SP Query would look somewhat like, SPQuery stateQuery = new SPQuery(); stateQuery.Query = "<Where><Eq><FieldRef Name=\"Zone\"/><Value Type=\"Text\">North</Value></Eq></Where>"; SPListItemCollection stateCol = StateList.GetItems(stateQuery); In the code above the StateCollection object gets populated with the States only related to North zone. You can then bind this collection to a GridView or DataList or any other similar controls to view the actual values. http://www.mindfiresolutions.com/Sharepoint-SPQuery-30.php[^]

        Cheers, Eliza

        1 Reply Last reply
        0
        • M Member 3836567

          User the following code to get username. The username is usually in "domain\\username" format. SPWeb oWeb = SPContext.Current.Web; SPUser sUser = oWeb.CurrentUser; string sUserName = sUser.LoginName Use the following method to remove extra slashes. public string getUserName(string strLogin) { string str = ""; // Parse the string to check if domain name is present. int idx = strLogin.IndexOf('\\'); if (idx == -1) { idx = strLogin.IndexOf('@'); } string strDomain; string strName; if (idx != -1) { strDomain = strLogin.Substring(0, idx); strName = strLogin.Substring(idx + 1); } else { strDomain = Environment.MachineName; strName = strLogin; } return strName; } } Check if it is working for you with or with out removing extra slashes. If you are looking for help with SPQuery let me know. -Susheel Dakoju

          E Offline
          E Offline
          elizas
          wrote on last edited by
          #4

          For instance, let us take a State List which holds all the states of India. States are grouped under different zones i.e. North, South, East & West. If I need to retrieve all the States for North zone then my SP Query would look somewhat like, SPQuery stateQuery = new SPQuery(); stateQuery.Query = "<Where><Eq><FieldRef Name=\"Zone\"/><Value Type=\"Text\">North</Value></Eq></Where>"; SPListItemCollection stateCol = StateList.GetItems(stateQuery); In the code above the StateCollection object gets populated with the States only related to North zone. You can then bind this collection to a GridView or DataList or any other similar controls to view the actual values. http://www.mindfiresolutions.com/Sharepoint-SPQuery-30.php[^]

          Cheers, Eliza

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups