21

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


15

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


15

There are a couple of methods for this available in the object model without the need to handle the slashes etc yourself, one method using MakeFullUrl: var fullUrl = item.ParentList.ParentWeb.Site.MakeFullUrl(item.ParentList.DefaultDisplayFormUrl); Parameters strUrl Type: System.String A string that specifies the server-relative URL. ...


13

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


11

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


11

UserProfile.PersonalSite property gets the personal site of the User: var profileManager = new UserProfileManager(ServerContext.GetContext(SPContext.Current.Site)); var profile = profileManager.GetUserProfile("domain\\username"); using (SPSite personalSite = profile.PersonalSite) { var personalSiteUrl = personalSite.PersonalUrl; }


10

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


10

Next time you perform the changes to the ContentType make sure to push changes to the lists while updating the ContentType. For now, you might need to perform some clean-up job here, just to make sure the field is deleted from all the lists, with your Custom ContentType. Use the following PowerShell script for clean-up! Vårsegod :) Add-PSSnapin Microsoft....


9

When running inside RunWithElevatedPrivileges, do not use SPContext.Current. Instead create a new SPSite object, passing in SPContext.Current.Site.Url.


8

You can check SPWeb.UIVersion to see what UI version the site is currently using: switch(web.UIVersion) { case 3: // 2007 break; case 4: // 2010 & 2013 "14 mode" break; case 15: // 2013 break; }


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


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 https://stackoverflow.com/questions/31326/is-there-a-browser-equivalent-to-ies-clearauthenticationcache


6

Rafal, You can use: Microsoft.SharePoint.Administration.SPAdministrationWebApplication centralWeb = SPAdministrationWebApplication.Local;


5

I had the same problem today when copying. Difference for me I was copying from one column to another. Both columns were managed metadata columns pointing to the same managed metadata. The reason I kept getting the error was because the column I read in was a Managed Metadata that allowed multiple values, the second column didn't. Therefore Specified ...


5

Link to document content type is what you want as Marius mentioned. You can extend the content type to include any metadata you need allowing you to have different sets of metadata for the same file in different locations.


5

You can use the CAML query from the default view if you want, but note that you're then using both the sort order as well as any filtering from that view. var query = new SPQuery(); query.Query = list.DefaultView.Query; var items = list.GetItems(query);


5

You need to call context.executeQueryAsync And then try to get the item count in the success method. UPDATE You are not specifying the query in SP.List.getItems(query_); Example: var clientContext = new SP.ClientContext(siteUrl); var oWebsite = clientContext.get_web(); this.collList = oWebsite.get_lists(); list = collList.getByTitle('Urgent Alerts'); var ...


5

It looks like you are writing a server-side object model code in your custom application page that uses SPSite or SPWeb objects but you didn't dispose these objects and this is cause wasting system resources. so try to dispose these objects to release its allocated memory as the following: To dispose SPWeb object, it's preferred to use Using statement as ...


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

Apparently this is a known issue. I ended up using the following method that I found here, to resolve the issue: DataTable CreateDataTableFromListItemCollection(SPListItemCollection itemCollection) { DataTable tbl = new DataTable(); if (itemCollection.Count > 0) tbl.TableName = itemCollection[0].ParentList.Title; ...


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

Check this out for when and how to use SPUserToken and SPSecurity.RunWithElevatedPrivileges. Impersonation in SharePoint : An Extreme Overview


4

using (SPSite site = new SPSite(<siteUrl>) { using (SPWeb web = site.OpenWeb()) { SPList list = web.GetList(<imageUrl>); SPListTemplateType templateType = list.BaseTemplate; int templateTypeInt = (int) templateType; } }


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


4

No. If you do, you might actually get an error, because the using statement under "TheCallingFunction" would call dispose on "web" after "DoSomethingRad" already called "Dispose()". As a rule of thumb, you have to look at your public method as a black box that just does what you expect it to do. To follow the Single-Responsibility Principle just do "...


4

To view who has opened documents, you can run a Audit Log report. This is can achieved using the Audit Log reports You go to the following setting: Site Actions > Site Settings > Site Collection Administration > Audit Log reports. Check Configure audit settings for a site collection


4

Even though SPWeb is declared outside of try catch block, it is initialized inside try block. And it is disposed inside try and finally blocks. So there won't be any memory leak. Only issue I see in the code is that in the finally block, there should be a null check before an attempt is made to Dispose SPWeb object. finally { if (newCommunitySite !...


3

Please see the description and implementation of Repository pattern implemented in SharePoint Guidance Library for 2007 (http://msdn.microsoft.com/en-us/library/ff648864.aspx). In 2010 version, they recommend to use repositories with Linq-to-SharePoint, but it works for easy cases and then require a lot of fixes to do simple things. And to support both ...


3

SPSite.LastContentModifiedDate might be what you are looking for http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spsite.lastcontentmodifieddate.aspx


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