November 6, 2009

Backup and Restore site in MOSS 2007

It happens to everyone that you need to move the same Microsoft Office SharePoint (MOSS) site to new location. At this time you can use the inbuild commands to backup the site from existing location and restore it to somewhere else.

MOSS has a powerfull command "stsadm" using that you can do it easily.

To use stsadm commands, open the command prompt and navigate to

c:\program files\common files\microsoft shared\web server extensions\12\bin


To Backup Site type the command

stsadm -o backup -url http://servername:portnumber/siteName -filename DestinationFolderPath/Backup Filename(c:\backupfilename)

This command will create a file to destination folder containing backup of the source site.

Once you have the backup file, that can be restored in MOSS by a single commands as below in sequence.
Steps to Restore Site
  • Create a web application and create a site with same site template using Central Administrator which you have backed up.
  • Type the command
stsadm -o restore -url http://servername:portnumber/siteName -filename backupfilepath(c:/backupfilename) -overwrite

This will restore the site to your defined location.

"Make sure you have full rights on the content database to take backup or restore site"

If you have any questions you can reach out our SharePoint Consulting team here.
By: Piyush

November 3, 2009

Display Full Error Description at Runtime in SharePoint 2007

Many times in SharePoint you will stuck at default error page. It says “An unexpected error has occurred” for all kind of errors.


This is very annoying part of SharePoint.

In such case, as a developer or professional, you have two possible ways to find out the exact error.

1) Go to Start > Control Panel > Administrative Tools > Event Viewer and check the internal error message, coz SharePoint itself logs all errors here.

Or

2) If you want to see the error on screen, you can edit configuration settings mentioned below.



• Navigate to web.config file of your SharePoint site.

In Windows Explorer, browse to the following folder

c:\inetpub\wwwroot\wss\virtualdirectories\site directory\site port number\

• Open web.config file in visual studio or notepad.

• Find word ‘CallStack’ and change status false to true

• Again find ‘CustomErrors ’ word and change mode On to Off

• Save and close the web.config file.

Refresh the error page, you will see original error message in screen instead of "An unexpected error has occurred" page.

If you have any questions you can reach out our SharePoint Consulting team here.

By: Piyush

November 2, 2009

Programmatically configure custom contact list value to Outlook 2007 using Web Part

It is inbuilt functionality in SharePoint ‘Action’ menu ‘Connect to outlook’. This functionality used stssync protocol and JavaScript function ‘ExportHailStorm’.


Many times you need some customized functionality like Connect SharePoint contact list to outlook 2007.

I searched many sites but none helped me to find the perfect solution but the show me the way to achieve this.

Here is code for that how to modify inbuilt ‘Connect to outlook’ functionality in under webpart.

To implement this, write function in Creatchildcontrol method in web part.

//code here

Protected override void Creatchildcontrol ()

{

OutlookButton.Attributes.Add("onClick", "javaScript:OutlookContactSync('Contacts'

,'" + SPContext.Current.Web.Url + "', '/Lists/GeneralContact/'

, '" + SPContext.Current.Web.Lists["GeneralContact"].ID + "'

, 'GeneralContact'

, '" + SPContext.Current.Web.Title + "');");

}

Protected override void Render (HtmlTextWriter writer)

{

OutlookButton.RenderControl (writer);

writer. Write (javascriptpath);

}



Add the following JavaScript function that will be used to call the method you mentioned above.

//JavaScript function

function OutlookContactSync (type, baseUrl, listUrl, listId, listName, siteName)

{

var outlookURL = encodeURI ('stssync://sts/?ver=1.1&type='+type+'&cmd=add-folder&base-url='+baseUrl+'&list-url='+listUrl+'&guid={'+listId+'}&site-name='+siteName+'&list-name='+listName+'');

Var objWindow=window.open (outlookURL,'','width=0, height=0');

objWindow.close ();

}

If you have any questions you can reach out our SharePoint Consulting team here.

Set master page from current site context in ASPX pages Runtime

Sometimes you create ASPX page and host it into SharePoint site, I mean you copy and paste it in _layouts folder.

If you want your ASPX Page is running within the SharePoint context (within a site) and you want to set current master page to your ASPX page, here are the steps that can be followed seamlessly.
What you need to do is, set the master page during the OnPreInit method of the ASP.NET page lifecycle

//Here is code for set master page in ASPX page

public partial class ABC: System.Web.UI.Page
{
SPWeb webspweb;

Protected override void OnPreInit (EventArgs e)

{

//call the base class method first

base. OnPreInit (e);

//applied runtime master page to the current page

webspweb = SPControl.GetContextWeb (Context);

this.MasterPageFile = webspweb.CustomMasterUrl;

}

}

The main think to keep in mind is the OnPreInit method where we applied the master page from the current site (SPWeb).

LAYOUTS applications are always called in the context of a site: http://…/sitename/_layouts/MyApp/Default.aspx

Happy Coding J

If you have any questions you can reach out our SharePoint Consulting team here.

By: Piyush