Tag Info

Hot answers tagged

8

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\"/>" + ...


7

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


5

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


4

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


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

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


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

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 built in way via the SharePoint JavaScript Object Model according to my research. Likely you will have to build your JavaScript to work with the SharePoint 2010 Alerts Web Service: http://msdn.microsoft.com/en-us/library/websvcalerts(v=office.14).aspx using JQuery or whatever framework calls from JavaScript on your page.


2

You can access all sorts of things in SharePoint by typing in a url or by merely changing the querystring. If the list must be hidden always, then change security on the list so that only those with proper permissions can see it. If you really are set on this, you can also implement some form of URL Rewriter on the IIS server hosting SharePoint and block ...


2

Items + Folder count Can you check out whether SPFolder.Itemcount could help to get the number of items in a list including the subfolders? - http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spfolder_members.aspx Only Item Count Then checking the SPListItemCollection.Count will give you the list items excluding the folders. - ...


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

If you have a language pack applied and your site is not in english, try updating the SPList.TitleResource property, using SPUserResource.SetValueForUICulture. Also, if you are looking at the quick launch or top navigation links, those get a copy of the value once set and might retain the old value even if you change the list's name.


2

ListAdded event runs asynchronously (whereas ListAdding is synchronous). The properties may not be available for updating. This post describes an alternative using ListAdding - Working with ListAdding and ListDeleting Events. I had a similar Event handling situation with ItemAdded/ItemAdding in a Document library where it worked fine under UI but not for ...


2

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. 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 class. I didn't figure out any way of ...


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

This means $web.Lists[$ListName] returns null. The reason is that you should pass title, not list root folder name or list url, to the SPWeb.Lists[string] indexer. For example: $list = $web.Lists["My precious list"] I assume 2012SalesReport1Q in your code refers to the list root folder name, i.e. it has address http://portal/Lists/2012SalesReport1Q. In ...


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

An SPList object is like a window into data stored in the Content Database. So what you're asking is effectively "Can I have a window without a house"? In short, the answer is that this isn't possible; you'll need to find an alternative method of holding your data, such as a List of Dictionaries: List<Dictionary<string, object>> ...


2

Programatically use SPQuery and in your caml query use the OrderBy Node eg: <Query><OrderBy><FieldRef Name="yourcolumn" Ascending="True" /></OrderBy></Query> You can also set the RowLimit property of SPQuery to 1 to make it more efficient Hope this helps UPDATE: As Nadeem Yousuf mentioned on another answer, this will not ...


2

You need to order by the column (descending), then set the query's rowlimit to 1: <OrderBy> <FieldRef Name="YourColumn" Ascending="FALSE" /> </OrderBy> From here: SO: MAX query using CAML


2

No, there will not be an error. I commonly use this design pattern to keep my using blocks small. SPList list; using (SPWeb web = SPContext.Current.Site.OpenWeb("myweb")) { list = web.GetList("/myweb/Lists/Awesome Name"); } SPListItemCollection items = list.Items; If you are updating an SPListItem in a manner that requires SPWeb.AllowUnsafeUpdates = ...


2

try this: foreach(SPListItem item in splist.Items) { foreach(SPField field in splist.Fields) { SPListItem newItem=splist.Items.Add(); newItem[field.ID]=item[field.ID]; newItem.Update(); } }


2

You can try following: foreach (SPListItem item in query) { SPListItem newItem = list.Items.Add(); foreach (SPField field in list.Fields) { if (!field.ReadOnlyField) newItem[field.Id] = item[field.Id]; } newItem.Update(); }


2

You can use FullTextSqlQuery like it's described in this post or KeywordQuery like it's described in this post. How to choose between these two approaches you can find here.


1

Solved! Sort of... I never figured out how to get the list items from xData.responseXML. However, simply replacing it with xData.responseText instead was enough to get the code working. Now find("z\\:row") finds all the list items as expected. Works in both ie,ff and chrome. I ended up modifying the contents of the each-loop a bit though. Here's the ...


1

Retrieve data only If you're only querying the items in these list then consider the following two alternatives to looping through everything: If you can live with the delay caused by crawling use search to gather the items. If not and you're in the "normal" situation where if a user has access to any sub site he also has at least some access to the site ...


1

From your comment it would seem that your problem is on the line: var collWebs = oSiteCollection.AllWebs; That call requires the user to have access to the web instances you are enumerating - it will fail as soon as you try to access a web site the user doesn't have access to. It is also useless to try to use workarounds like ...


1

Check if user has permission to the web before you "use" the web, SPWeb.DoesUserHavePermissions is the method you want. Example - if(oWebsite.DoesUserHavePermissions(SPBasePermissions.Open)) using (oWebsite) { //code } kindly let me know if it worked.


1

Your missing adding the field as fieldlink to the Lists version for the content type var ct = list.ContentTypes["NameOfCT"]; var fieldLink = new SPFieldLink(newField); ct.FieldLinks.Add(fieldLink); ct.Update() When you're using content types in a list only the fields corresponding to the content type is shown in forms. But all fields can be shown in ...



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