SharePoint CAML asks for the Created field with username

Hi, I have a form for administrators where they insert the username ("domain \ name"), and the code receives and installs some information from it.

This is a huge project, and some of the lists contain the username as a string ("domain \ name"), but some lists are taken into account only in the "Created" column, which is automatically created.

I want to know what is the fastest way to request these lists using the username string. I tried to use the same query as the one I use for the first type of lists, and it obviously didn't work -

<Where><Eq><FieldRef Name='UserName'/><Value Type='Text'>domain\\username</Value></Eq></Where>

Thank.

+5
source share
2

"" , ( " " ). "" - "", <FieldRef Name='Author'/> . , , "Created_x0020_By". , , , , , , .

"Created By" - , ID;#Full Name. , " " , ( , ). , <FieldRef Name='Created_x0020_By'/>. , "" , , , SharePoint. , .

<Eq><FieldRef Name='AssignedTo' /><Value Type='Integer'><UserID Type='Integer' /></Value></Eq>

. , "AssignedTo" "Author" <UserID Type='Integer' /> .

+16

:

  • SharePoint-User, EnsureUser, ..:

     SPUser myUser = SPContext.Current.Web.EnsureUser(@"DOMAIN\USERNAME");
    
  • SharePoint:

     SPQuery spQuery = new SPQuery();
     StringBuilder queryString = new StringBuilder(String.Empty);
     queryString.Append(@"<Where>");
     queryString.Append(@"   <Eq>");
     queryString.Append(@"       <FieldRef ID=""{1df5e554-ec7e-46a6-901d-d85a3881cb18}"" LookupId=""True"" />"); //Author Field
     queryString.Append(@"       <Value Type=""Lookup"">" + myUser.ID + @"</Value>");
     queryString.Append(@"   </Eq>");
     queryString.Append(@"</Where>");
     spQuery.Query = queryString.ToString();
    
  • myList.GetItems(spQuery);
    
+7

All Articles