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

October 28, 2009

Apply Custom Policy file to SharePoint Web Part

At the time of deployment of webpart, it is not possible for you to deploy DLL in GAC or have FULL trust level in the selected website.

In such case you can use custom policy file to come out from the problem.
Here are the steps to apply custom policy file to for your webpart(s).
·        Navigate to 12 hive\config folder.
·        Take a copy of WSS_Minimal.config file
·        Rename to [CompanyName]_minimal.config.
Open the new config file and add below code lines into the file as per given location. Add below code

 </NamedPermissionSets>

<CodeGroup class="FirstMatchCodeGroup" version="1" PermissionSetName="Nothing">

<IMembershipCondition class="AllMembershipCondition" version="1" />

<!-- New Code Lines added -->

<CodeGroup class="UnionCodeGroup" version="1" PermissionSetName="FullTrust">

<IMembershipCondition class="StrongNameMembershipCondition" version="1" PublicKeyBlob="[Paste your Public Key BLOB]">

</IMembershipCondition>

</CodeGroup>

<!-- New Code Lines completed -->


Save the file. Don’t close it.

You need to add Public Key’s Blob file in addition to the above lines. To create the Blob you can follow the step below.

Open Start > All Programs > Microsoft Visual Studio 2005 > Visual Studio Tools > Visual Studio Command Prompt.

Type the following command
sn -p YourStongNameFile.snk PublicKeyOnly.snk

Where YourStongNameFile.snk is Your Projects SNK (Strong Name Key) file and PublicKeyOnly.snk is New creted PublicKey 

After you run the above command run the beloow command to create Blob:

 sn -tp PublicKeyOnly.snk

You will get your PublicKey's BLOB like below sample

 0024000004800000940000000602000000240000525341310004000001000100f9edc

57832372d0722d0ac9c068a482b47070d01b98ef1d7edd12eeec895e2a3d361220aef6

81d18c0cff1b2a9e606a18d968f6d4cceb148077c961d3e014a22b4049fb9c49c424f39e

6f192b27d961978ea766734432ce913b003b4085d7be21be2c570aa7c5a17506a25dac

84c2dd1ff037c22e147ab7ac563498b8602f8cf

 Copy this new blob and paste in config file in place the text “[Paste your Public Key BLOB]
that you kept open.

Save and close the config file.

  • Put your config file in 12 hive\Config folder.
  • Open you existing config file of your site and add one tag in config file under WSS_Medium,WSS_Minimal trust levels tags.

<securityPolicy>

<trustLevel name="WSS_Medium"  policyFile="C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\config\wss_mediumtrust.config" />

<trustLevel name="WSS_Minimal" policyFile="C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\config\wss_minimaltrust.config" />

<!—Newly added code lines à

<trustLevel name="CompanyName_Minimal"  policyFile="C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions \12\config\CompanyName_Minimal.config" />

<!—Newly added code lines end à

Now you have reached to the last step of the configuration,  change Trust Level WSS_Minimal to [CompanyName]_Minimal.

<trust level="CompanyName_Minimal" originUrl="" />

Save and close the config file.

Thats it J

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

October 26, 2009

Enable Anonymous access in your SharePoint site

Many times you create websites in SharePoint. You assign different ports to access the site.

But what if you want to make the site internet facing and you want other to access the site with logging in to your site?

Yes this is possible.

Here are the steps to make a website as internet facing website.

1. Open Central Administration website of MOSS and navigate to

Central Administration > Application Management > Authentication Providers

The screen will look like below:




2. Select your web application that you want to enable anonymous access, from web application dropdown as displayed in below image.




3. Click on “Default” under Zone column. This will redirect to a new page. Check “Enable Anonymous Access” and click “Save” button.


4. Close Central Administration site.

5. Open the website that you selected for anonymous access. Login using administrator rights and navigate to Site Actions > Site Settings > People and Groups

6. Click “Site Permissions” from quick links. This will open up a new page as here:




7. Click on Settings under page header. Select “Anonymous Access”.




8. Close the browser and you are done.

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

By: Alpesh

Display data using SharePoint List GUID

If you have to show data from SharePoint List using CAML (Collaborative Application Markup Language) required looping thru each item in list. This method takes bit long time to execute when you have large data in list.


Here is the one of the simple method to retrieve data from a SharePoint List by user selected view that doesn’t require CAML.

I have given some abstracts here:

// My list name is VerbList
// GUID of the list is F9037F57-6DEB-4BA8-B1BA-85A0995DE882

SPList listName;
DataTable ListDataTable=new DataTable();
SPListItemCollection listItemColl=
listName.GetItems(qry, "{ F9037F57-6DEB-4BA8-B1BA-85A0995DE882}");
ListDataTable =listItemColl.GetDataTable();

In above syntax code lines

listName is object of SPList,where my data is stored.

qry is Query for which data to be displayed.

F9037F57-6DEB-4BA8-B1BA-85A0995DE882 is the GUID of the SPView from where I have to fetch data.

Make sure you use the GUID in Upper Case.

Retrived data will be stored in ListDataTable, you can use the data as you wish.

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

October 15, 2009

How-To: Add intellisense support for Jquery inside UserControl page in Visual Studio 2008 IDE

If you have just downloaded and referenced Jquery , you might be wondering how to add intellisense support for the same in user control.


A blog post by scott gu shows very nicely how microsoft has included a hotfix for visual studio 2008 sp1 which enables jquery intellisense support (provided you also reference the jquery vsdoc file in your project).



I was trying out JQuery on normal aspx page and it worked just fine. However I soon ran into problem while using it in a user control, the intellisense simply was not working. I did a quick work around for the same which is as follows:

Just write down if statements within your user control which evaluates to false always and reference the jquery script file there. Note I already have a referenced jquery lib in my master page, and I don’t want it to be rendered a second time here, hence the if statement.

This code will server two purposes: firstly it will allow visual studio IDE to detect and display intellisense when you use jquery syntax in your user control, secondly it won’t show up in the rendered html since if always evaluates for false.


 
 
 
There may be other optimal solutions available out there, but this code did the trick for me and it can be removed before publishing the site for production purposes.

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

Posted By: Bhavyesh