Tag Info

Hot answers tagged

16

This is related how instance of SPListItem is being created. Actually in both cases new item is added to the collection of items in list, in first case new item is added explicitly, in the second one implicitly. The point is, that for initializing collection of items in list is used the same method GetItems but with different queries. ...


5

You can use the SPWeb GetFile method to retrive the SPFile located at a specified url. Try something like this: SPFile file = SPContext.Current.Web.GetFile(string.Format("{0}/{1}", x, y));


3

This answer has two parts: First, for maximum performance and scalability, to retrieve the lists you should be using web.Lists[Guid]. Iterating through web.Lists and picking your selected lists, or using web.Lists[Name] (which also iterates through the set internally) will causes the API to retrieve metadata for all SPList objects under that SPWeb, which ...


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

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


2

There is no buildin way to get all the lists in a site collection. Your method of looping through AllWebs and getting the Lists collection for each is the only way, but it's not efficient, so you probably want to build some cache or maintain your own list and updated it using a EventReceiver each time a list is create/delete or when a site is deleted. But ...


2

Blockquote I don't like using [0] to get the SPListItem...interested in reccomendations Well, SPList.Items[0] syntax fetch ALL THE DATA from SharePoint and after - give you item by index. That's a common behavior. You might use also SPList.GetItemById or similar methods or even make a caml query against the target list w/ SPList.GetItems method. It's ...


2

Alternatively, you could use SPFieldLookupValue (for a single lookup) and SPFieldLookupValueCollection (for a multi-lookup) to parse the field values using SharePoint's built-in methods for processing them. Here is a revised version of your function for single lookups: protected string RemoveCharacters(string fieldValue) { SPFieldLookupValue value = ...


2

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


2

The value of an Url field is stored internally as an url/description couple. What you are fetching is the string representation of that value. To obtain the actual values, the preferred way is to use the SPFieldUrlValue class. You need to create a new istance of the class from the field string value - you will then be able to read the desired url and ...


1

To help improve the performance of a large list or library, you can index up to 20 columns. In general, an index on a column enables you to quickly find the rows you want based on the values in that column, even when working with millions of items. When you combine indexes with filtered views, you can quickly retrieve the items you want. It ...


1

For this you need to increase the Threshold value first and then get the list item count. You can increase it either programmatically or powershell or Central admin. Ex.. through powershell $WebApplication = Get-SPWeb http:// $List = $WebApplication.Lists["My List"] $List.EnableThrottling = $false $List.Update() ...


1

HandleEventFiring handleEventFiring = new HandleEventFiring(); handleEventFiring.DisableHandleEventFiring(); try { var parentDoc = documentLibrary.GetItemByUniqueId(parentId); parentDoc.Delete(); } finally ...


1

You can get items collection very simply. Try this code: public static SPListItemCollection GetItemsRecursive(SPFolder folder) { SPList list = folder.ParentWeb.Lists[folder.ParentListId]; SPQuery query = new SPQuery(); query.Folder = folder; //set folder for seaching; query.ViewAttributes = "Scope=\"Recursive\""; ...


1

From the SPList, grab the RootFolder property (http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.splist.rootfolder.aspx). In the RootFolder (an SPFolder) use Files property to get the SPFileCollection in the folder (http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spfolder.files.aspx). Then on the RootFolder (and each subsequent ...


1

Working solution from StackEchange link var context = SP.ClientContext.get_current(); var myListItem = context.get_web().get_lists().getByTitle("ListName").getItemById(1); context.load(myListItem); context.executeQueryAsync(function(){ alert(myListItem.get_item("HyperLinkFieldName").get_description()); ...


1

If you are looking to limit the number of items returned by the server object model and at the same time build some kind of paging UI, use SPQuery.ListItemCollectionPosition property. http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spquery.listitemcollectionposition.aspx This following article cover its usage in details: ...


1

This is not working for you? SPQuery query = new SPQuery() { Query = "<OrderBy><FieldRef Name='FullName' /></OrderBy><Where><Contains><FieldRef Name='FirstName' /><Value Type='Text'>e</Value></Contains></Where>" }; SPList oList = web.Lists["Profile"]; SPListItemCollection items = ...


1

Okay straight of why did you include both for loop and spquery remove the for loop for the list items , i.e on foreach(SPListItem Discussion in DiscussionList) , use only spquery since you are searching on the discussion list anyways. Also , if it helps you can use rowlimit on Spquery class f you dont want all the items. Modified code would look like : ...



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