Hot answers tagged

27

Fastest way to delete all items is to batch together all delete commands... public static void DeleteAllItems(string site, string list) { using (SPSite spSite = new SPSite(site)) { using (SPWeb spWeb = spSite.OpenWeb()) { StringBuilder deletebuilder = BatchCommand(spWeb.Lists[list]); spSite.RootWeb....


25

No, you can not change internal name of column. You have to delete old column and create new column if you want to change column name


11

If you use linq to object, you always retrieve ALL records from DB. It is not good if you have got a lot of data. To reduce records you can use CAML query: SPQuery query = new SPQuery(); query.Query = "<Where>" + "<Eq>" + "<FieldRef Name=\"FileLeafRef\"/>" + "<...


11

Nothing in SharePoint is simple and this question proves it. I spend last hour or so on this hoping to find some remotely simple solution. (See update for SharePoint 2013 below) ImageUrl is not a 'native' SPList property. I did some decompiling and refactoring only to find out that ImageUrl is one of the many list properties retrieved by SPListCollection ...


10

I found answer for my question. private string GetAttachmentUrls(SPListItem oItem) { string path = string.Empty; try { path = (from string file in oItem.Attachments orderby file select SPUrlUtility.CombineUrl(oItem.Attachments.UrlPrefix, file)).FirstOrDefault(...


8

check this out: 1. Go to the list that is lacking the link 2. Select the view that doesn’t have the link appearing 3. Select Edit Page from the Site Action menu 4. Edit the list web part properties 5. Note the current Toolbar setting 6. Change the Toolbar setting and click Apply. Any selection other than No Toolbar should cause ...


8

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


7

How about using paging with the 'old' listdata.svc? It supports paging with the ODATA skip and top parameters like so: http://sharepointsite/_vti_bin/listdata.svc/MyList?$skip=100000&$top=10000 Then you can pull e.g. 10,000 items at a time and iterate over the list contents. This is supported in SharePoint 2010, 2013 and Online.


6

I ran into the same requirement in a recent project, basically preventing access to any list view or form of a particular (hidden) list via the Web browser. SharePoint designer isn't allowed on Web Application level and Web services (including client object model) is blocked by a custom HTTP handler, so the concerns mentioned in other answers didn't apply ...


6

If you don't want to use the GUID, you'll have to make an extra call and get the vti_listname property from the list folder. The folder you can get by url using the getFolderByServerRelativeUrl on the SP.Web object. Example: var clientContext = SP.ClientContext.get_current(); var web = clientContext.get_web(); var folder = web....


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

SPWeb.Lists.Count.ToString(); is correct way to find number of Lists for any SPWeb. You might be seeing in difference in count you see here and in Site is because SharePoint has couple of hidden list like UserInformation list, managed metadata list which are hidden from UI. Also we can hide our custom list by using powershell/server side code. To give an ...


5

Depends on whether you mean fastest to execute or fastest to code and get working. As mentioned the batch method will execute fastest, otherwise to do it the way you were doing then this would be quicker: while(list.Items.Count > 0) { list.Items[0].Delete(); }


5

When you call SPList.Items.Add() it will fetch all list items through an SPQuery. This can be very costly when you have a considerable amount of items. // Microsoft.SharePoint.SPList public SPListItemCollection Items { [ClientCallableExceptionConstraint(FixedId = "c", ErrorType = typeof(SPQueryThrottledException), Condition = "There is a throttle ...


5

Using SPList.Items property is bad practice. Each time the property is accessed, it requests all items with all fields from database. Instead you should always use SPList.GetItems(). SPList.GetItems(params string[]) - you can use it to load only the fields that you need. As far as I remember it'll only return items in the root folder of the list. SPList....


4

1)Select Edit Page from the Site Action menu 2) Edit the list web part properties 3)settings window opens and change the Toolbar type to "Full Toolbar" which can be seen in the dropdown. click ok and click stop editing on the top of the page . you can see "add new item" link button.


4

After some effort I converted it into PowerShell YAY! [Microsoft.SharePoint.SPList] $list = $web.Lists["Stakeholders Register"]; if(($list.Fields["Job Number"] -ne $null) -and ($list.Fields["Role within project"] -ne $null)) { $fieldReorderable = [string]::Empty; $fieldNonReorderable = [string]::Empty; $firstField = "...


4

No, as you can see from the msdn documentation, the SPList object does not have a "Property Bag" property. That said, if you need to, a common workaround is using the property bag of the root folder of the list as a surrogate. You see... SPFolder does define a property bag. Also you can take for granted that a (normal) list or document library should have a ...


4

I did something like this for a client. My solution was made a web service. By this web service I was able to make an AJAX call and create an Alert code behind.


4

If you want to get the collection of "field_name + field_value", you can try: var fieldValues = currentItem.get_fieldValues(); It returns an object, the object key is field name and the object value is field value.


4

MONTH( [MyDate] ) will return 1 for January, then use the SharePoint version of the switch/case statement: =CHOOSE( MONTH([MyDate]) , 30 , 60 , 60 , 60 , 60 , 60 , 60 , 60 , 60 , 60 , 60 , 60 ) remember: if you are going to work with Dates in JavaScript then January = 0 and December = 11 All SharePoint functions: www.viewmaster365.com/functions ...


4

If both lists are same, you can use SharePoint designer workflow to copy list item from one list to other. Below link may help you to get started: http://blogs.salmanghani.info/copy-item-workflow-using-sharepoint-designer-2010/


4

This is because of the SPWeb.Lists.Count.ToString(); return the number of all lists and libraries not only lists To can get the accurate number of lists only you should exclude the library and other list types from your code as the following int listcount=0; foreach (SPList list in Web.Lists) { if (!list.Hidden & list.BaseType != ...


4

While the other two answers here are correct in that it is fairly straightforward to hide the fields conditionally based on the Title value, what I think is going to be more of a problem for you is that you say that when all 6 fields are shown, they are all required. This presents a problem, because if you make them required fields in the list, if you hide ...


3

ok, it seems that the solution is to return number as string and replace comma with dot - apparently with ProcessBatchData regional settings of the site are not used, so I had to provide the number with standard english-version format


3

A SharePoint list lives in one site and one site only. But depending on your needs the content of the list can be displayed in other sites invarious ways. Content Query Web part Share a List View Between Sites in SharePoint 2010 implementing a simple Cross SIte collection list view webpart Page view web part showing view page (add ?IsDlg=1 to url to get ...


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


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


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