Hot answers tagged

30

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


13

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


7

Generally speaking you will want to use SPQuery to only query items you're interested in. Unless you're doing SPList oList = web.GetList("XYZ"); for(int i=0; i < oList.Items.Count; i++) { string strLstItemName = oList.Items[i].Name; // << BAD, as you use Items here, so you fetch them from DB each loop } there shouldn't be any relevant ...


6

Make sure that the column you include in the where clause is defined as an indexed column in SharePoint. You can check by going to the list you're querying and into List -> Settings -> Indexed Columns. It's not applicable in your CAML query, but if you have more than one 'where', ensuring the first where hits an indexed column can increase efficiency. ...


6

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));


4

You can use: if (bool.Parse(item["ShowTitle"].ToString()) == true) or if (item["ShowTitle"].ToString() == true.ToString())


3

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


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

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

You could sort list items using array.sort function: function getListItems(listTitle,success,error) { var ctx = SP.ClientContext.get_current(); var list = ctx.get_web().get_lists().getByTitle(listTitle); var items = list.getItems(SP.CamlQuery.createAllItemsQuery()); ctx.load(items); ctx.executeQueryAsync(function() { success(items); ...


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

You have to iterate through DataTable and fill into SPListitemCollection object. Also check following link for the code details: http://social.technet.microsoft.com/Forums/sharepoint/en-US/f772b759-28b7-4330-b4a2-ef7541f3e79c/how-to-convert-datatable-into-splistitemcollection


2

The above mentioned techniques would have only work if DataTable would have been derived from SPListItemCollection. Since its not the case, so you will have to iterate over the rows in DataTable and will have to create list items for each row and associate it with appropriate properties.


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


2

There are two options in sharepoint to delete the listitem: listitem.Recycle() deletes the list item and puts it in the recycle bin listitem.Delete() deletes the item permanently If you delete a document in SharePoint using the User Interface, it’s being moved to the Recycle Bin, so that it can be restored if necessary. Calling the SPListItem.Delete() ...


2

You can use the Order By in CAML: <OrderBy> <FieldRef Name = "ID" Ascending = "TRUE"/> </OrderBy> <Where> ... </Where>


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

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

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

As long as you stick to the principle of storing the SPListItemCollection in a variable before looping through the items, the difference between using for instead of foreach is close to redundant. The foreach loop will be converted into a for loop under the hood. It's a 1, perhaps 2 sec, difference. So if you write: var listItems = ...


1

Loop into the data table and remove additional characters foreach (DataRow row in dataTable.Rows) { row["Your Coumn Name"] = ReplaceByRegex(row["Your Coumn Name"]) } Just write a function what replaces additional characters using Regex. Currently, I am unable to write the whole method. Try and let me know.


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

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

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

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

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


1

I think this should work: SPFolder folder = myItem.File.ParentFolder; SPFileCollection items = folder.Files;



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