Tips n Tricks

Securing Publishing Internet Sites – ViewFormPagesLockDown Feature

In Internet facing websites, you don’t want anonymous users to access pages such as AllItems.aspx etc. There is a Sharepoint feature ViewFormPagesLockDown which can be enabled to secure your sites. Find out more details about this feature at: http://technet2.microsoft.com/Office/en-us/library/f507f5d6-4c9d-4f98-909f-069c53b9a3f61033.mspx#section6
Activate Feature:
stsadm -o activatefeature -url <site collection url> -filename ViewFormPagesLockDown\feature.xml
De-Activate Feature:
stsadm -o deactivatefeature -url <site collection [...]


Sharepoint Object Model Best Practices

Follow the below best practices while doing custom coding using sharepoint object model. I found these articles very useful.
1) Best Practices: Common Coding Issues When Using the SharePoint Object Model
http://msdn.microsoft.com/en-us/library/bb687949.aspx
2) Best Practices: Using Disposable Windows SharePoint Services Objects
http://msdn2.microsoft.com/en-us/library/ms473633.aspx


How to activate or deactivate feature using sharepoint object model

To activate feature through Sharepoint object model use the following code
Activate a feature:
spSite.Features.Add(“featureId”)
Deactivate a feature:
spSite.Features.Remove(“featureId”)


How to Log errors to SharePoint Log file

In SharePoint log files are available under \Common Files\Microsoft Shared\web server extensions\12\LOG.

Exceptions can be logged to the default SharePoint log file using the following line of code.
Microsoft.Office.Server.Diagnostics.PortalLog.LogString(”Exception Occurred: {0} || {1}”, Ex.Message, Ex.StackTrace);

Note: Make sure that you add the reference to Microsfot.Office.Server dll


How get the process ID of a SharePoint application if multiple web Applications are running

You can run IISAPP utility from the command prompt which will list  all the w3wp processes, their Application Pool Id and process ID.

This is helpful when you want to attach w3wp process to a debugger ,and when multiple web Applications are running.