I want to pull datas from list with queries. I want to use many queries with C# code. And there is QueryString in C#. I want to use it. So how can i do this.
2 Answers
If you have a Visual Web Part and placed it in a page called http://myspsite/pages/WebPart.aspx then form the url with passing the Query String Parameter like
http://myspsite/pages/WebPart.aspx?MyParam=test
then to get this value from web part page PageLoad function call
string myParam = Request.QueryString["MyParam"];
this will give you the passed value in the query string. then you can pass this values in CamlQuery filters dynamically to retrieve list items.
Use Request.QueryString to get querystring.
Request.QueryString["parameter1"];
Build your query with dynamic values.
Sample code:
Server side object model:
SPQuery query = new SPQuery();
query.Query = @"<Where><And>
<Eq><FieldRef Name='ProjectCode' /><Value Type='Text'>"+queryValue+@"</Value></Eq>
<And>
<Eq><FieldRef Name='AssignedTo' LookupId='True' /><Value Type='Int'>" + user.ID + "</Value></Eq>" + @"
<Or><IsNull><FieldRef Name='TriggerFromTimerJob' /></IsNull><Eq><FieldRef Name='TriggerFromTimerJob' /><Value Type='Choice'>NO</Value></Eq></Or>
</And>
</And></Where>";
Client Side CAML:
CamlQuery query = new CamlQuery();
query.ViewXml = @"<View><Query>
<Where>
<Eq><FieldRef Name='users' /><Value Type='User'>" + queryValue + @"</Value></Eq>
</Where>
</Query><RowLimit>100</RowLimit></View>";
SharePoint CAML schema
https://msdn.microsoft.com/en-us/library/office/ms467521.aspx