Hot answers tagged

12

It sure looks so from your story, but isn't there a quite easy workaround for this? <Where> <Or> <In> <FieldRef Name="ID" /> <Values> <Value Type="Number">1</Value> <Value Type="Number">2</Value> . . . <Value ...


8

If you use CAML to get list items (which is the fastest way of retrieving items), it is just enough to get ids of items to be able get the count: //some query var title = "<Eq><FieldRef Name='Title' /><Value>task 00001</Value></Eq>"; var q = "<Where>" + title + "</Where>"; var lst = web.Lists["Tasks"]; var query = ...


7

The MSDN documentation for the SPQuery class has a code example of using SPQuery to interrogate a list. Here is the code sample in case it changes over time: using (SPWeb oWebsiteRoot = SPContext.Current.Site.RootWeb) { SPList oList = oWebsiteRoot.Lists["Tasks"]; SPQuery oQuery = new SPQuery(); oQuery.Query = ...


7

If you read these two pages, you'll see that the two different properties require different structure. http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spquery.viewxml.aspx http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spquery.query.aspx You'll see that ViewXML is the full Query, thus needs the View and Query tags, whereas the ...


5

That looks like it should work. I know it's not optimal but, as an alternative, you could do the sorting on the client side. var items = list.GetItems(query).OfType<SPListItem>().OrderByDescending(i => i["ContentType"]);


5

Ok, I'm turning my comment into answer. Onse in a while we all are making a typos - to solve your problem you should use "Status" instead of "status" in 3rd <Eq>.


4

Try this SPFieldUser assignedto = mySourceList.Fields["AssignedTo"] as SPFieldUser; ... ... foreach(SPListItem ...) { if(!UserDetails...) { SPFieldUserValue assignedUser = assignedto.GetFieldValue(mySourceListItem["AssignedTo"].ToString()); if(assignedUser != null) { string name = ...


4

You don't use ViewFields inside the Where clause in a CAML query. See Query Schema and SPQuery.ViewFields Property Also, the And around the IsNotNull node is doing nothing. The And needs two child elements to operate correctly.


4

This is a well known and very difficult to solve problem, especially when it comes to large volumes of data. Even not touching SharePoint, you might have noticed that many systems (Google is an obvious example) return only approximate number of filtered elements. Basically the only thing you can do is to perform the same query but exclude permissions and ...


4

AFAIK it's not documented anywhere which fields should be included to be able to do an Update after querying with ViewFieldOnly set to true, but according to SPQuery.ViewFieldsOnly and Updating an SPListItem it's amongst other ID, UniqueID, object type, ... BUT my recommendation is definitely don't even try, just set ViewFieldsOnly to false, then you're ...


4

Yes, it's a shame that sharepoint don't have EndsWith. As for answer you can develop a custom web part: Use CAML query to reatrive all that contain 'Internet' via <Contains> Results that were provided will only contain those that have 'Intranet' and you can iterate over each item and check if it ends with Internet String.EndsWith . The worst case ...


4

Regardless of the Fields listed in the ViewFields, SPQuery has always returned extra fields including ID, and a few other system related fields as well as auto-retrieving linked fields for computed columns etc. The ViewFieldsOnly allows you to really only return the exact fields specified. The downside is that the returned item may no longer be updateable ...


3

You're disposing an instance of SPWeb got through using SPContext. This probably will result in unpredictable behaviour as something else is expecting to dispose of the Site object you've got it from. Rather, use new SPSite(SPContext.Current.Site.Url) and wrap that in a using tag like you've done there. EDIT: Yeah, you're using OpenWeb() which does indeed ...


3

There is no memory leak in your code for SPWeb. The SPWeb object you get from SPContext.Current.Site.OpenWeb(webUrl) should be disposed (like you already did). There is are other performance improvements I can suggest in your code: 1) Use list = web.GetList(lstUrl) instead of list = web.Lists[listName] ; 2) Use list.GetItems([SPQuery]) instead of ...


3

1) You don't need the ViewAttributes node in your example, as you're targeting a single list. 2) Your pages will be 2000 items long with your current RowLimit attribute 3) You have the throttle mode set to Strict when infact you disable throttling the line after - try it without these settings omitted and logged in as Admin first. 4) Have you tried a ...


3

You get that error when the fields used in CAML query fields or viewfields are not present in that list. CAML uses the internal name and not the display name. Verify that the ticketid is the internal name of that field and not display name. Go to list settings and click on the field ticketid and observe the url for the param value 'field'. This should match ...


3

You have to use SiteDataQuery as replied by Thomson above. Here is some sample code SPWeb web = SPContext.Current.Site.RootWeb; SPSiteDataQuery query = new SPSiteDataQuery(); //Server template for page library is 850 query.Lists = "<Lists ServerTemplate='850' Hidden='TRUE' />"; query.ViewFields = @"<FieldRef Name='URL' Nullable='True' ...


3

The query in your code is searching for items where field named Hidden has value set to TRUE. My guess is that your list doesn't have field named Hidden. I will answer your question with some code: //Always make sure you dispose SPSite and SPWeb objects using (SPSite site = new SPSite("http://mycoolsite")) { using(SPWeb web = site.OpenWeb()) { ...


3

Or statements are notoriously inefficient, even directly in SQL. Since the error is related to memory it seems you're hitting a hardware limit rather than any kind of built-in limit. With this in mind, I'd recommend using a more efficient query structure, such as the <In> element to work around the issue.


3

My understanding is that the schema of the list and fields defines whether or not a field is sortable. For ContentType field "Sortable" (that's a boolean attribute) must have been set to False. That's the reason it is not available when you create view for your list; the field is not available in the dropdown. Same restrictions would apply to SPQuery also. ...


3

Your CAML query is missing an angle bracket before /Value.


3

My understanding of how the List View Threshold works is limited, however, I suspect the reason your CAML query is failing is because it is filtering on the non-indexed field, and the RowLimit is applied "after". I think that indexing the CheckoutUser field would solve your problem, however it sounds like you have a lot of sites. Allow me to suggest an ...


3

myQuery.RowLimit = 0 I think if I'm correct: 0 = unlimited Hope this helps. :)


3

Can't comment due to low rep so posting as an answer, purists forgive. Breaking a 500 element In into several nested Or tags does not work, to my despair. The limit is 500 elements hard apparently. I have tried breaking using a limit of 500 elements, 400, 300, 200, 100, and the SPServices query failed, returning: 500 Internal Server Error with the ...


3

How about creating the SPQuery object using the constructor where you can pass the appropriate SPView. http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spquery.spquery.aspx You could then add a query to include the appropriate items, something like:- var query = new SPQuery(spView); query.Query = ...


3

Your code looks like Server Object Model. Based on my experience on using CAML queries, I can suggest you to get rid of <Query> tags. So update your query as below Query = "<Where>" + "<Eq>" + "<FieldRef Name='ows_PostID' LookupId='TRUE'/>" + "<Value Type='Lookup'>" + ...


2

Add to your code query.ViewAttributes = "Scope=\"RecursiveAll\""; Change your CAML to: <Where> <And> <Or> <Eq><FieldRef Name="FileDirRef" /><Value Type="Text">firstFolder</Value></Eq> <Eq><FieldRef Name="FileDirRef" /><Value ...


2

Try using SPListItemCollection.GetDataTable like this: var dt = list.GetItems(oQuery).GetDataTable(); gridView.DataSource = dt; When you just use list.GetItems(oQuery) as the DataSource what the GridView gets is a SPListItemCollection which it doesn't understand, but it's an IEnumerable which it understands. So now the GridView can enumerate the ...


2

As Hugh said, in the getSelectedList function you have the first error. using (myWeb) { SPListCollection myLists = myWeb.Lists; foreach (SPList myList in myLists) { if (myList.Title.Equals(ListTitle)) rList = myList; } } myWeb.Dispose(); This will dispose the myWeb istance after the using block. The suggested way from ...


2

Glolita, Use SPGridView instead of ASP:GridView... Here is a nice article: How to use the SPGridView filter together with a SPDataSource I also noticed in every example in CAML before <Query> they are using <View>, but I don't know if this is really the problem... can you please try that as well Also, SPTypes.DataSourceMode="List" Hope ...



Only top voted, non community-wiki answers of a minimum length are eligible