I want to pass the spuser as a paramter to the caml query
but when i tried the below code its throwing error:
using (SPWeb spWeb = spSite.OpenWeb())
{
SPDocumentLibrary objDocLibProjDocLibrary =
spWeb.Lists.TryGetList("ProjectDocumentLibrary") as
SPDocumentLibrary;
// string strsingleProjCodeStageTupleSet =
"VGIL_NPR_TBD_STB_050_2017";
//"VGIL_NPR_EMD_STB_993_2017";//"VGIL_NPR_EMD_STB_999_2017";
string strstage1 = "Concept And Design Proto
Developement";//"Feasibility and Kick Off"; //
string strnp11user =@"mydomain\NPD11";
string strsingleProjCodeforptp =
"VGIL_NPR_TBD_STB_050_2017";
SPUser objuser1 = spWeb.EnsureUser(strnp11user);
//objuser1.LoginName
string strPTPQueryforPDL = "<Where><And><Eq>"
+ "<FieldRef Name='ProjectCode' />"
Value Type='Text'>" + strsingleProjCodeforptp + "</Value>"
+ "</Eq><And><Eq><FieldRef Name='AssignedTo' />"
+ "<Value Type='User'>" + objuser1.LoginName + "
</Value></Eq><Or><IsNull>"
+ "<FieldRef Name='TriggerFromTimerJob' />"
+ "</IsNull><Eq>"
+ "<FieldRef Name='TriggerFromTimerJob' /><Value
Type='Text'>NO</Value>"
+ "</Eq></Or></And></And></Where>";
SPQuery oQueryProjDocLibCodeStage = new SPQuery();
SPListItemCollection
oListItemCollProjDocLibProjCodeStage;
oQueryProjDocLibCodeStage.Query = strPTPQueryforPDL;
oListItemCollProjDocLibProjCodeStage =
objDocLibProjDocLibrary.GetItems(oQueryProjDocLibCodeStage);
int counterprojdoclibstage =
oListItemCollProjDocLibProjCodeStage.Count;
if (oListItemCollProjDocLibProjCodeStage != null &&
oListItemCollProjDocLibProjCodeStage.Count > 0)
{
foreach (SPListItem singleProjDocLibCodeStageItem in
oListItemCollProjDocLibProjCodeStage)
{
int idofmatchingprojdoclib =
Convert.ToInt32(singleProjDocLibCodeStageItem["ID"]);
}
}
it seems , "" + "" + objuser1.LoginName + "" line of query is throwing error.
in order to get the correct items after caml query execution, what should be written ? i cant hardcode the spuser values
am using NTLM authentication . i tried with the below query as well:
string strPTPQueryforPDL = "<Where><And><Eq>"
+ "<FieldRef Name='ProjectCode' />"
+ "<Value Type='Text'>" + strsingleProjCodeforptp +
"</Value>"
+ "</Eq><And><Eq><FieldRef Name='AssignedTo' />"
+ "<Value Type='Integer'><UserID>" + objuser1.ID + "
</UserID></Value></Eq><Or><IsNull>"
+ "<FieldRef Name='TriggerFromTimerJob' />"
+ "</IsNull><Eq>"
+ "<FieldRef Name='TriggerFromTimerJob' /><Value
Type='Text'>NO</Value>"
+ "</Eq></Or></And></And></Where>";
that also failed!
<Eq><FieldRef Name='AssignedTo' />"
+ "<Value Type='User' LookupId='True'>>" + objuser1.Id+ "</Value></Eq>
also didnt work Which one is the correct caml query to get the actual result count?