Tag Info

Hot answers tagged

29

You would never use RootWeb in the context of a using statement and OpenWeb() isn't useful unless the URL specified in the SPSite constructor was a sub web of the site collection in lieu of just the site collection URL. So, you should never do this: using (SPWeb web = site.RootWeb) { // do something with web } ...and OpenWeb() is useful in a scenario ...


12

One of the problems with content types (there are quite a few!) is that the design with site and list content types works very poorly with the declarative (XML) approach. If you just update your Content Type manifest and re-install the feature new content types will be affected, but not all the list content types already "instantiated" from the site content ...


10

The usual recommendations for using RWEP are to Avoid using SPSecurity.RunwithElevatedPrivilege to access the SharePoint object model. Instead, use the SPUserToken to impersonate with SPSite. Only use SPSecurity.RunwithElevatedPrivilege to make network calls under the application pool identity. Don't use it for elevation of privilege of SharePoint ...


9

Thus far, using the object model has been the only way I have been able to successfully do this. I encountered the same issues as you when using PowerShell. Using Jaspers' post SP2010: Setting BCS column and related fields as my guide, I used the following code to iterate through all the items in my Resumes document library, read the value from the ...


9

From the point of view of an experienced developer there is no major difference but there are points to consider. Code approach: More friendly for new developers, cause VS environment provides good features for investigating new API You can debug it step by step, comment and use Watch tools, in comparison with XML where you just see the result Before XML ...


8

This might end up as a 'whatever floats your boat' kinda question. I will add though, that whatever you choose, make sure it's consistent throughout the entire solution. Remember that creating Content Types programmatically is done at Feature Activated level, which is after Feature XML is processed, so if you're provisioning Page Layouts, you'll need to ...


7

SPQuery by no way will make your code slow, infact every other SharePoint article on net advice you to use SPQuery to gain Performance. To make things still more interesting GetItemByID internally use SPQuery to fetch the Item back to you,following is part of code taken from the GetItemByID function SPQuery query = new SPQuery(); query.Query = ...


7

I think you can use SPSiteDataQuery to enumerate all files in all document libraries of one SPSite. This will prevent folder recursion and raise the speed. For example, you can query Guid for each item, and then enumerate all files using SPWeb.GetFile. SPSiteDataQuery query = new SPSiteDataQuery(); // All document libraries query.Webs = "<Webs ...


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


7

There are two possibilities here: 1) You need to determine if field is completely custom (added to list by a user from GUI). You can use SourceId property for this purpose. You will get Url, starting with "http://schemas.microsoft.com" for standard fields, and some random GUIDs for custom fields. Sample code: SPField field = // get your field from a list ...


6

There's probably a bunch of different ways to do this, but here's a snippet from some C# code that I wrote a while back converted to PowerShell. Hope it's along the lines of what you're looking for: Start-SPAssignment -Global $web = Get-SPWeb "http://sharepointdev:90" $list = $web.Lists.TryGetList("Site Pages") foreach ($file in $list.RootFolder.Files) { ...


6

there are several good ways of retreiving data. Each has its pros and cons. Typically Search would be used when you want to list some, but not all, data (not all can be exposed) and when you want to retrieve data across site collectons. SPQuery, SPSiteDataQuery and PortalSitemapProvider are good candidates if you are on the same site collection. See some ...


6

Take a look on msdn foreach (SPUser user in group.Users) { group.RemoveUser(user); } But be aware that you change this group for the whole Sharepoint installation.


6

Leading on from @tylerrrr07's answer, there's another overload of GetItemsWithUniquePermissions which may be of use to you: MSDN: SPList.GetItemsWithUniquePermissions Method (int maxItemToReturn, bool folderOnly) You could then avoid the potentially huge result set from running the method by using the following: SPList.GetItemsWithUniquePermissions(1, ...


6

In IE (version > 6) SignOut.aspx uses ClearAuthenticationCache as a client side command. This does not work for Firefox. I found this example on StackOverflow that might work for you http://stackoverflow.com/questions/31326/is-there-a-browser-equivalent-to-ies-clearauthenticationcache


5

Using API, you won't have any limitation on what you can done. Using Web Services you will be able to do a lot of things, but mainly concerning structure and/or data query Using Rest services, you will only be able to perform CRUD operation. It actually depends on you requirements. There is also a 4th way, that requires a bit of more work : use the OOB ...


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


5

Best practice is to use SPQuery on the list to return list items that match your criteria. See the software performance boundaries documentation here has some details (pertaining to 2007): http://technet.microsoft.com/en-us/library/cc287790%28office.12%29.aspx 2010 info is here: http://technet.microsoft.com/en-us/library/cc262787.aspx There was another ...


5

In a way yes - try using the "Link to a document" content type instead of the document. or use the "Send To" option which would create a syncronized copy of the document (multiple locations possible) which can be easily maintained. In the case of Send To, yes, i believe -which should also answer your 3rd question (but if not) Hope it helps, C:\Marius


4

SPWeb.Users.GetByEmail() and SPWeb.Users.GetById() is only going to return the users that have logged in to your site. Try the method SPWeb.EnsureUser(). MSDN says the following: Checks whether the specified logon name belongs to a valid user of the website, and if the logon name does not already exist, adds it to the website.


4

Take a look at Property Class There are two types of user profile properties: Regular - Defines the property data type and the corresponding user profile flags. Section - Property that serves as a separator for user interface grouping purposes. In order to move properties 'into' section you just need to reorder them. I am providing a ...


4

Try the following code to get the items based on the folder, using(SPSite site = new SPSite("site url")) { using(SPWeb web = site.OpenWeb()) { SPFolder folder = web.GetFolder("/Docs/folder1"); if(folder.ItemCount > 0) { SPList list = web.Lists.TryGetList("ListName"); SPQuery query = new SPQuery(); query.Folder = folder; ...


4

The SPList.BaseTemplate property tells you what list definition was used to create a given list. Also, LINQ is by far the most efficient way to query all the lists in your site -- and this could obviously be extrapolated to query all lists within an entire site collection too (see Example 2 here). Creating nested "foreach" loops to manually enumerate all ...


4

You can retrieve the system account by SPSite property SPContext.Current.Site.SystemAccount Basicaly EnsureUser method uses logon name (Domain\User_Alias) of the user.


4

You have to find the ID SPRecycleBinItem and use SPRecycleBinItemCollection.Delete or find the SPRecycleBinItem and use SPRecycleBinItem.Delete This code deletes any instances of Test.png from the folder Test in the documentlibrary with rootfolder TestDocs from the recyclebin: using (var site = new SPSite("http://sp2010")) { var idsToDelete = new ...


3

The rule is complicated, but in a nutshell, you should dispose of any object that you create yourself that implements the IDisposable interface. In the context of SharePoint, this includes: Any SPSite object you create using siteColl.OpenWeb(), returned by SPSiteCollection.Add, by the SPSiteCollection[] index operator, or yielded in a SPSiteCollection ...


3

If you stick in a Quick Add Group with the same name as your "wide" one, it'll show up at the top of the list by default when someone tries to add a web part in that zone. However, it will show up as normal further odwn the list when someone tries to add to another zone. However, I don't think it's actually possible to do this at all - the only method I ...


3

You haven't specified what your actual problem is, unless you are wondering why the variable "web" is an object. The reason it is an object is because you defined it as a "var", not an SPWeb. If you built your foreach loop like this: SPWeb currentWeb = SPContext.Current.Web; foreach (SPWeb web in currentWeb.Webs) { // web is now an SPWeb object. }


3

Are you using MOSS or WSS only? If you have MOSS, have you tried the Content Query Web Part? If you really need to use the object model, you could try the SPSiteDataQuery class http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spsitedataquery.aspx


3

You could use the "Hidden" properties the query also returns, WebId, ListId and (Item)ID. These are returned by default for each result in an SPSiteDataQuery/ Then open the web using the WebId, then the List by it's ListId (convert both to GUIDs of course) and the item by ID. By sorting the result by webid, listid, id, you can speed up any iterations done ...



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