1

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.

  • are you trying to use it in App ? or Visual Web Part ? that is Client side Object model or Server Object Model – Esaki Sep 28 '17 at 6:16
2

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.

2

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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