Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Here's my query to get current user task using CAML but it's not working

SPUser me = web.CurrentUser; SPList list = web.Lists["Tasks"]; SPQuery qurey = new SPQuery(); qurey.Query = @" "+ me.Name +"Not Started"; SPListItemCollection items = list.GetItems(qurey);

share|improve this question

3 Answers 3

SPWeb oWeb = SPContext.Current.Web;
string currentUser = oWeb.CurrentUser.Name;
SPQuery query = new SPQuery();
query.Query = "<Where><Contains><FieldRef Name=\"AssignedTo\" /><Value Type='Text'>" +        
currentUser  + "</Value></Contains></Where>"
share|improve this answer

To get the tasks for the current user you should use a CAML query like:

<Where>
  <Or>
    <Eq>
      <FieldRef Name='AssignedTo' LookupId='TRUE'/>
      <Value Type='Integer'><UserID /></Value>
    </Eq>
    <Membership Type='CurrentUserGroups'>
      <FieldRef Name='AssignedTo'/>
    </Membership>
  </Or>
</Where>

like this:

query.Query = "<Where><Or><Eq><FieldRef Name='AssignedTo' LookupId='TRUE'/><Value Type='Integer'><UserID /></Value></Eq><Membership Type='CurrentUserGroups'><FieldRef Name='AssignedTo'/></Membership></Or></Where>";
share|improve this answer

You can do it this way:

  SPWeb oWeb = SPContext.Current.Web;
  string currentUser = oWeb.CurrentUser.Name;
  SPQuery query = new SPQuery();
  query.Query = "<Where><Eq><FieldRef Name=\"AssignedTo\" /><Value Type='User'>" +        
  currentUser + "</Value></Eq></Where>"
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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