Tuesday, November 17, 2009

Backup and Restore using stsadm.exe

You can backup & restore using below ways.
  1. Using STSADM.exe command.
  2. From Central Administrator Backup & Restore.
Backup - Restore using STSADM command
Open Start > Run > type "cmd" OR "command"
then type "cd C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN"
Then you can use command as per your requirement.
Backup Site Collection
stsadm -o backup -url http://webapplication/SiteCollection/" -filename "C:\backupFolder"
Restore Site Collection
stsadm -o restore -url http://webapplication/SiteCollection/" -filename "C:\backupFolder"
Backup Farm
stsadm -o backup -directory "C:\FarmBackupFolder\" -backupmethod Full
Restore Farm
If you want to overwrite existing farm use stsadm -o restore -directory "C:\FarmBackupFolder\" -restoremethod overwrite
If you want to restore new farm use
stsadm -o restore -directory "C:\FarmBackupFolder\" -restoremethod new

Monday, July 13, 2009

WebPart Printing

3 Easy Steps to Print your WebPart

  1. Add Content Editor WebPart on your WebPart page in which you want to Print.
  2. Click on Modify Share WebPart then click Source Editor's button and add below code for Print Button.

    < type="button" onclick="javascript:void(PrintWebPart())" value="Print Web Part">
    < language="JavaScript">
    //Controls which Web Part or zone to print
    var WebPartElementID = "WebPartWPQ6";
    //Function to print Web Part
    function PrintWebPart()
    var bolWebPartFound = false;
    if (document.getElementById != null)
    //Create html to print in new window var PrintingHTML = '\n\n';
    //Take data from Head Tag
    if (document.getElementsByTagName != null)
    var HeadData= document.getElementsByTagName("HEAD");
    if (HeadData.length > 0)
    PrintingHTML += HeadData[0].innerHTML;
    PrintingHTML += '\n\n\n';
    var WebPartData = document.getElementById(WebPartElementID);
    if (WebPartData != null)
    PrintingHTML += WebPartData.innerHTML;
    bolWebPartFound = true;
    bolWebPartFound = false;
    alert ('Cannot Find Web Part');
    PrintingHTML += '\n\n';
    //Open new window to print
    if (bolWebPartFound)
    var PrintingWindow = window.open("","PrintWebPart", "toolbar,width=800,height=600,scrollbars,resizable,menubar");
    // Open Print Window Printing
    < /script>

  3. Find your Web Part DIV ID using View Source on WebPage.

    Ex. - open your WebPart Page and right click on this then click on View Source and then find your WebPart
    using Ctl+F. Then you can get DIV id of your WebPart copy this and Paste on above code mark in Bold line.

    //Controls which Web Part or zone to print
    var WebPartElementID = "..........";

Click here for more details.

Friday, April 24, 2009

Create Custom Policy File for SharePoint WebPart

Now you can run your code without modify FULL trust in WEB.Config file.
Below Steps to create Custom Policy File for WebPart.
  • Copy WSS_Minimal.config fole from ...\12\Config\ folder.
  • Rename to MyCustom_minimal.config.
  • Now Add below Code to this config file as per given location.

Add below code

Code Start Here Code End Here
  • Now Create Your PublicKey's Blob file as per below.
  • Open VS's command Promt and RUN below Command

sn -p YourStongNameFile.snk PublicKeyOnly.snk

YourStrongNameFile.snk = Your Projects SNK
PublicKeyOnly.snk = New creted PublicKey

Now Create Blob as below command.

sn -tp PublicKeyOnly.snk

Now your PublicKey's BLOB created like below (here Example)

Copy New Blob and past in above config file.

  • Put your config file in ...\12\Config\ folder.
  • Add one tag in config file below WSS_Medium,WSS_Minimal trust level like below.

    Also change Trust Level WSS_Minimal to MyCustom_Minimal.

Saturday, April 4, 2009

Create SharePoint WebPart using Visual Studio SharePoint Extension

  • Install Visual Studio SharePoint Extension.
  • Open Visual Studio and create New Project > Select SharePoint as Project Type > Select Web Part project template.
  • Then open Webpart1.cs file and add below things in render method.

protected override void Render(HtmlTextWriter writer)


writer.write("My First Web Part.");


  • Open Property Window of this project and Go TO Debug Tab and add your site URL to Start browsing with URL http://MyPC:100/MyFistSite/" (As per below Image)

  • Right Click on Project in Solution Explorer and Select Deploy.
  • After Successfully Deploy open your SharePoint site and Add Your First Web Part on your Web Part Page.

Very Easy to work with SharePoint Web Part.