Tag Info

Hot answers tagged

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

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 = ...


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 ...


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 ...


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

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 = ...


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

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 = ...


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

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 ...


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.


2

You might want to look at U2U CAML Builder or Stramit CAML Viewer to help build your CAML. It seems like you might want to apply a content type filter instead of looking at every folder individually.


2

SPListItems is not included in auditlog (per design due to performance issues) so you cant use auditing if you are looking for list items. I would probably go for SPSiteDataQuery (as you mention yourself) which usually performs best for site-wide queries. Another option would be the GetListItems web service which often i surprisingly fast... A third ...


2

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()) { ...


2

If your WCF is located under '_layouts' folder and configured correctly you have access to the SharePoint object model as in web parts, application pages, etc. So you can use list.GetItems(spQuery) method to filter items. You can read more about WCF services and SharePoint here. How to configure your service you can find in this post.


2

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 ...


2

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 ...


2

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 ...


2

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.


2

I really don't see a way you can do this...not with a CrossListQuery anyway. If you were doing this against a single list (i.e. SPList.GetItems(SPQuery) then you could add: <Eq><FieldRef Name='FileDirRef'/><Value Type='Text'>"ListName"</Value></Eq> and that would pull back only the top level folders, as the folders under ...


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 ...


2

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 ...


1

When you create something in a using statement, it gets disposed afterwards. using(myWeb) {...} myWeb.Dispose(); You should take off the using statement, and also check to see if the myWeb is disposable. using (SPWeb myWeb = mySite.OpenWeb()) This instance of use is correct and will auto dispose myWeb.


1

Use SPList.GetItems(SPQuery query) instead. Apply filters, if appropriate, and specify only the fields you need to make the query more efficient. If the list contains more than 2,000 items, you will need to paginate the list in increments of no more than 2,000 items. The following code example shows how to paginate a large list. This implies ...


1

If you use SharePoint Server 2010 and not SharePoint Foundtation you can enable SharePoint Publishing Infratstucture that will give you "Manage Content and Structure" there you can delete up to 1000 items at once. You can also access "Manage Content and Structure" with the following url: http://www.yourservernamehere.com/_layouts/sitemanager.aspx When you ...


1

If you have a look at the definition of the SPList.GetItems(SPQuery,string) method: http://msdn.microsoft.com/en-us/library/ms434064.aspx You can see that the second parameter needs to be the GUID of the view enclosed in curly braces. Eg: {B080E5D2-DEF9-11E1-8A8D-550A6188709B} Try the following code: string viewGUID = ...


1

What is important here is to get the datetime format right. If you use it programatically you could either use this string sendDate = sendDate.ToString("yyyy-MM-ddTHH:mm:ssZ"); ..or you could use the SPUtility.CreateISO8601DateTimeFromSystemDateTime method to achieve the same. Beyond this you could also consider using "relative" expressions based on ...


1

Create your query with the U2U Caml Query builder: http://www.u2u.be/Tools/wincamlquerybuilder/CamlQueryBuilder.aspx (This works with 2010 as well) Ideally the following query should work: <Query> <Where> <And> <Geq> <FieldRef Name="SendDate" /> <Value IncludeTimeValue="TRUE" ...


1

Yes that's right. CamlQuery is a class in the Microsoft.SharePoint.Client.dll which is part of the Client Object Model which can be used through a .NET, Silverlight or JavaScript Application. While SPQuery is part of the Microsoft.SharePoint.dll which can be used on the Server Side in Farm or Sandbox solutions through Custom C#/.NET code.


1

You're right SPQuery is part of the Server Side API and CamlQuery is part of the Client Object Model. So if your code is running on a server in the SharePoint Farm you can use SPQuery. If your code isn't running on one of the servers, then you can use CamlQuery.



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