SPSecurity.RunWithElevatedPrivileges

If like me you’re wondering what exactly does SPSecurity.RunWithElevatedPrivileges, this is what I understand of it : SPSecurity.RunWithElevatedPrivileges( () => { using( var newSite = new SPSite( site.Url ) ) { // your stuff } }); Is equivalent to : using( var newSite = new SPSite( site.Url, site.SystemAccount.Token ) ) { // your stuff } So if this is just to open an elevated privilege SPSite, it will be equivalent. But if you do some more complex things, as soon as you load a new SPSite it will open it with the original UserToken. And you lose… ...

February 22, 2010 · Florent Clairambault

Threads and Sharepoint

When you are using threads on sharepoint, you should take care of some little things : The method used to launch the thread must have the “[STAThread]” attribute, it avoids some huge memory leaks. If you need to use an SPSite from the calling site, you should copy its URL and UserToken to build a new SPSite in the new thread. If you’re not using that “design pattern”, things will get really wrong. And of course you should dispose any sharepoint SPSite (SPWebs come from SPSite) allocated within the thread.

February 20, 2010 · Florent Clairambault

ANTS Memory Profiler

Well, I’m speaking about a commercial product again. This time it’s about ANTS Memory Profiler (by Red Gate software, the ones that made .Net reflector). This product will help you identify any .Net memory leak you could have. The truth is, .Net never leaks but you can sometimes make stupid conception mistakes, like forgetting to remove references of some objects (that may contains heavy references themselves). The tool allows you to take snapshots of your running application and compare different snapshots. You can see the difference of memory consumption by some objets or the difference of class instance count. ...

December 30, 2009 · Florent Clairambault

Sharepoint 2010 on my Windows 7

I finally took the time to make “Sharepoint 2010” work on my PC. I previously did the installation as recommended by the Microsoft. I had to do one additionnal thing to make it work : “Desactivate the .Net 4 ISAPI filter”. In the event logs, I had this error: ISAPI Filter 'C:\Windows\Microsoft.NET\Framework\v4.0.21006\aspnet_filter.dll' could not be loaded due to a configuration problem. The current configuration only supports loading images built for a AMD64 processor architecture. The data field contains the error number. To learn more about this issue, including how to troubleshooting this kind of processor architecture mismatch error, see http://go.microsoft.com/fwlink/?LinkId=29349. And then: ...

December 20, 2009 · Florent Clairambault

Inside Sharepoint

I recently took the time to take a look inside the Microsoft.Sharepoint.dll using reflector. I’m not sure I have the right to do that. And I’m pretty sure I don’t have the right to publish any code extracted from it, so I won’t show any. Using SPSite(s) and SPWeb(s) If you do some timing on the SPWeb creation call (SPSite.OpenWeb), you will find out that it’s freaking fast (less then 1 ms on my server). The reason is that the most heavy object, the SPRequest class, is shared among SPWebs of a SPSite. The Dispose call only “Invalidate” the SPWeb, and if this SPWeb is the owner of the SPRequest (which is SPContext.Current.Web object in most of the cases), it releases it. ...

August 4, 2009 · Florent Clairambault

Sharepoint : Using BaseFieldControl

What for ? Sharepoint’s API provides some standard form controls to render each column. This is the controls used to render the standard add and edit forms. And they all inherit the BaseFieldControl class. In other word: In any SPList, you have some SPField fields and each of these SPField has the super power to create a BaseFieldControl. Each BaseFieldControl is a CompositeControl containing ASP.Net controls. For a single line field, you will just have a wrapped TextBox. But for some more advanced fields like a multi-select lookup field (SPFieldLookup) or rich text field, it can generate some “complex” controls and their related javascript code. ...

July 28, 2009 · Florent Clairambault

Debugging on Sharepoint 2007

Sharepoint debugging isn’t fully automated. So you should really know how to debug and diagnose your assemblies in any given situation. 1. Attaching to the process It only applies to a debugging environnement. This is the one that everybody knows (or should at least). You deploy your DLL in the GAC, restart your application pool, access your sharepoint web application in order to load the application pool and the DLL and then attach to the right w3wp.exe process (or every w3wp.exe process if you don’t really know which one to choose). ...

July 26, 2009 · Florent Clairambault

Sharepoint : SPWebConfigModification

I’ve seen lots of Sharepoint software having an installation manual of at least 20 pages (sometimes 60). Most of the operations they describe could be fully automated. And these software were made by freaking big companies. They should be ashamed of themselves. Maybe they just forgot that computer science is all about saving some time (and not only making money). One good example is MOSS Faceted search 2.5 (I haven’t tested the 3.0). It takes at least 40 minutes to uninstall this crap. Why isn’t it just ONE WSP or at least one BAT file launching the WSP installation and the other steps ? Is there any real reason for that ? ...

July 19, 2009 · Florent Clairambault

Sharepoint 2010

Finally, Microsoft decided to communicate on Sharepoint 2010 on their website. Wow, they really seem to have understood all of the sharepoint developers problems. Look at the full developer video. Everything is incredible : Sharepoint Extensions seem complete and cutomizable, there is the new developper dashboard which displays for instance the number of opened SPRequest the time spent on each loading stage of the page, the Business Data Catalog model allows to use any data inside sharepoint within “external lists”, the official LinQ for Sharepoint, the new WSP package which allow to specify which deployment actions to use. This runs on top of Windows Server 2008 and Visual Studio 2010. ...

July 18, 2009 · Florent Clairambault

Sharepoint – Updating webparts

I’ve talked about this before. When you create versions of webparts, you have two main solutions to update existing webparts : Create a binding redirect within the web.config file. Update each and every webpart instance of the collection site (or just the site). The first one is really the best solution : It’s simple and very fast. But, it applies to the whole Web Application. Sometimes, the client might want to only update the site collection or even the website. In this case, we need to apply the second solution : update each webpart. ...

July 6, 2009 · Florent Clairambault