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