Friday, July 1, 2011

Backup and Restore Site Collections in SharePoint 2010

Backup-SPSite http://SP –Path C:\Backup\siteCollection.bak


Restore-SPSite http://SP –Path C:\Backup\siteCollection.bak

Tuesday, June 28, 2011

Use SharePoint BLOB Caching to increase performance

BLOB caching, or disk-based caching, is an out of the box (OOTB) caching mechanism that is built into the MOSS 2007 and SharePoint Server 2010 platforms. It is commonly used to speed-up access to large and relatively static resources that are stored in content databases, such as images, videos, javascript files, and more. Performance improvements are gained by storing these assets on web front-ends (WFEs) once they’ve been requested by a client. This allows SharePoint to serve subsequent requests for such assets directly from WFEs instead of round-tripping to the content database each time a request for such an asset is received. For most SharePoint sites, this type of caching can significantly lighten the load on your SQL Servers and back-end network.

BLOB Caching is controlled through the web.config file for each of the IIS web sites that is associated with a Web application, and it is not enabled by default. Enabling BLOB caching is as simple as setting the enabled attribute to true in the web.config element as shown below.

<BlobCache location=”C:\blobCache” path=”\.(gif|jpg|png|css|js)$” maxSize=”10” enabled=”true” />

Thursday, June 23, 2011

SharePoint FxCop Rules

http://sovfxcoprules.codeplex.com/

SP0001 - Dispose created SPSite or SPWeb objects
SP0002 - Dispose SPWeb returned from a method
SP0003 - Do not dispose SPSite.RootWeb and SPWeb.ParentWeb properties
SP0004 - Dispose SPSite returned from the SPSiteCollection.Add method
SP0005 - Dispose SPSite returned from the SPSiteCollection index operator
SP0006 - Dispose SPWeb returned from the SPSite.AllWebs.Add method
SP0007 - Dispose SPWeb returned from the SPSite.AllWebs index operator
SP0009 - Dispose SPWeb returned from the SPWeb.Webs.Add method
SP0010 - Dispose SPWeb returned from the SPWeb.Webs index operator
SP0011 - Dispose SPWeb returned from the Area.Web property
SP0012 - Dispose the SPLimitedWebPartManager.Web property
SP0013 - Do not dispose SPList.ParentWeb when using the SPList.BreakRoleInheritance method
SP0014 - Close PublishingWeb returned from the PublishingWeb.GetPublishingWebs index operator
SP0015 - Do not dispose SPSite and SPWeb returned from the GetContextSite and GetContextWeb methods
SP0017 - Do not dispose SPSite and SPWeb returned from the SPFeature.Parent property
SP0018 - Close PublishingWeb returned from the PublishingWeb.GetVariation method
SP0019 - Dispose SPSite returned from the UserProfiles.PersonalSite property
SP0008 - Do not dispose SPSite.RootWeb when using SPSite.LockIssue, SPSite.Owner or SPSite.SecondaryContact properties
SP0016 - Do not dispose SPSite and SPWeb returned from the SPContext.Current.Site, SPContext.Site, SPContext.Current.Web and SPContext.Web properties

Adding List Items using PowerShell

SharePoint 2010 offers over 500 new cmdlets that we can use to automate the SharePoint 2010 environment through Windows PowerShell. The cmdlets go as deep as SPWeb, everything beyond SPWeb requires additional scripting, such as adding fields, views and items. Here’s an example showing how to add an item to the Announcements list in SharePoint 2010:

$spWeb = Get-SPWeb -identity http://SP
$spList = $spWeb.GetList(“Lists/Announcements")
$newItem = $spList.AddItem()
$newItem["Title"] = "My First Announcement"
$newItem["Body"] = "

PowerShell Magic

"
$newItem["Expires"] = "5/5/2010"
$newItem.Update()
$spWeb.Dispose()
In the example we use the Get-SPWeb cmdlet to bind to a specific site. Next we use the GetList() method to retrieve a list. The method accepts a lists relative URL as input. We then use the AddItem() method to create a new item in SharePoint 2010. Finally we use the Dispose() method on the SPWeb object to make sure that the object is disposed of correctly.

PowerShell commands for SharePoint 2010

>Get-Command -Noun SPSite
You can get the all PowerShell commands:

>Get-Help Get-SPSite
You can get the Name, Syntax, Description, Related Links, Remarks

To Retrieve content database for a specific site collection:
>Get-SPContentDatabase -Site http://SPServer01

Results:

ID :96dfa345-43df-3edg-bbc6-1l4e8ee105le
Name :WSS_content
Web Application :SPWeb Application Name=Sharepoint - 80
Server :SPServer01
CurrentSiteCount :2

To retrieve the content database for a specific Web Application:
>Get-SPContentDatabase -WebApplication "Sharepoint - 80"
Results:
ID :96dfa345-43df-3edg-bbc6-1l4e8ee105le
Name :WSS_content
Web Application :SPWeb Application Name=Sharepoint - 80
Server :SPServer01
CurrentSiteCount :2

Developer Dashboard in SharePoint 2010

DD will obviously not give you all answers you need to solve performance/page load issues (for instance you might have to talk to your SQL guru to optimize T-SQL queries or C# developer to optimize their webpart algorithm or tell your end user that they have put too many webparts on a page). In the end it will make the life of any user and a lot easier to understand page load in SharePoint 2010 and hence Project Server 2010.

Script to turn on/off DD (not do not turn it ON in your production server since it will activate it for all pages for all users in your farm!) (copy and paste in a file and save with .BAT extension then execute in your farm):

echo off

@SET UTILS_ROOT=C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\BIN

@echo ENABLE Developer Dashboard
@echo ================================================================

"%UTILS_ROOT%\stsadm" -o setproperty -pn developer-dashboard -pv ondemand

@echo DISABLE Developer Dashboard
@echo ================================================================

REM "%UTILS_ROOT%\stsadm" -o setproperty -pn developer-dashboard -pv off

PAUSE

Wednesday, June 22, 2011

AJAX References

http://www.msjoe.com/videos/microsoft-ajax/

  • ASP.NET 2.0 Ajax Extensions 1.0
  • Installed under C:\Program Files\Microsoft ASP.NET
  • In Visual Studio, create an ASP.NET AJAX Enabled Website (from a template)
  • Every page has an instance of the ScriptManager
  • Partial Page Update Pattern
  • UpdatePanel Control - server side control that enables us to place fires an event for the server to update the contents of the panel
<updatepanel></updatepanel>

<contenttemplate> ...some controls here...> </contenttemplate>

<triggers>
<asyncpostbacktrigger controlid="control to listen to" eventname="click">
</asyncpostbacktrigger>
</triggers>

ASP.NET Notes
  • Date.Now