Friday, October 3, 2008

Easy way to Redirect Users to an Error Page and Success page in SharePoint

While developing custom application Pages and web parts we mostly come across
the scenario for redirecting user to Some Error Page or Redirecting user to some
default page after successful operation.
WSS 3.0 provides a very easy and consistent way to provide this.
Just a single line of code; Below here is the sample code
 1. TransferToSuccessPage :
  SPUtility.TransferToSuccessPage("Operation was completed",
@"/Docs/default.aspx", "", "");




2 . TransferToErrorPage :

try
{
//Code that might cause an exception
}
catch (Exception ex)
{
SPUtility.TransferToErrorPage(ex.Message);
}

Monday, July 21, 2008

Multiple Lists Data into a Single data view - using SharePoint Desinger


Recently I came across a situation where we need to display a report with multiple SharePoint lists having one column “CategoryID” of type Number in common with minimum efforts or no code.

The environment expected for this solution was a Windows SharePoint Services 3.0; Which limits us from using Content Query Web part (which is MOSS only feature) with cross List Queries.

We came across a beautiful feature of Microsoft SharePoint Designer which facilitates to display data from multiple resources into a single Data View. http://office.microsoft.com/en-us/sharepointdesigner/HA100991441033.aspx

The sample explained here contains creating XML files for the Data Sources. Any Existing SharePoint Lists can be considered as a Data Sources.

Using this way we can easily create a dynamic view from multiple lists. Although the major disappointment here is : No Filter, No Sorting is supported. This will also not have Export to Excel feature as well

With Some play around using Microsoft SharePoint Designer on the Data View Web part we can achieve Grouping.




Sunday, June 22, 2008

How to remove the 'title column' from a SharePoint list?

Here by I am posting a very simple workaround to get rid of default column “Title” from any SharePoint List. When we create a SharePoint List, a default column “Title” gets created. While customizing Lists , we often come across a situation where we do not want this “Title” column.

The fist way to deal with this scenario can be :

  1. We can make it a non-required column and take it out of the default view and that way we will not have to deal with it anymore. However, we cannot delete it.
  2. Or When we customize our list, rename the Column name for “Title” with any of the needed column, which is required to be Single Line text.

Friday, June 20, 2008

Custom Site definition with WSP does not show custom lists on Quick Launch navigation bar.

Recently I came across a requirement where I had to create a custom site definition with custom lists , custom content types and document libraries. I found providing site definition as a WSP file is the best way and using SharePoint Solution Generator I created WSP file for my customized site. [ To learn how to use SharePoint Generator to create WSP files, refer link : http://weblogs.asp.net/soever/archive/2006/11/11/SharePoint-Solution-Generator-_2D00_-part-1_3A00_-create-a-site-definition-from-an-existing-site.aspx ]

My original site had few of my custom lists links available on Quick Launch Bar. And visual studio project created for the site also had SharePoint Solution settings Quick Launch Default Option as TRUE

When I created a Site based on this new site template (Development site template section), site did not had these custom lists availble on Quick Launch Navigation bar. Although custom List instances were available on the site.

As my search, it seems that Quick launch navigation customizations gets lost using SharePoint Solution Generator.
[Here is the good link illustrating limitations of SharePoint Solution Generator : http://www.mtelligent.com/journal/2007/10/13/overcoming-the-limitations-of-the-sharepoint-solution-genera.html ]

Fix: -

In Onet.XML file for the site definition file,

  1. Find Configuration section
  2. Find List element for your custom list definition
  3. Add attribute QuickLaunchUrl="Lists/MyCustomList/AllItems.aspx"
  4. Rebuild the application
  5. Deply the application to get new updated WSP file.

Friday, February 8, 2008

How to hide Upload Toolbar button from a Forms Library?

Last month, I came across a requirement where I need to hide Upload toolbar button on one of our forms library. I tried to find on net, and got some clues how to do this. Adding a custom control under c:\Program Files\Common Files\Microsoft shared\Web service extensions\12\Template\CONTROLTEMPLATES, this can be done.

Reference: http://blogs.msdn.com/dipper/archive/2006/10/05/How-to-Remove-or-hiding-items-in-List-toolbar-in-Sharepoint-Server-2007.aspx

But using this way, It hides toolbar buttons for all of the document library and Forms library. Following is the workaround to hide toolbar buttons on specific forms library.

Step 1: Design a InfoPath Form with some controls on it.

Step 2: Publish InfoPath form as a Site Content Type “MyCustomContentType” on Forms Template Library

Step 3: Using Visual Studio Sharepoint tools, Create custom list definition for Forms Library. Tool used is Visual Studio 2005 extensions for Windows SharePoint Services 3.0, Version 1.0) Tools for developing custom SharePoint applications.

Step 4: Under Schema.Xml add attribute ToolbarTemplate=”myToolBarID” to <View BaseViewID="1" > element as follows

<View BaseViewID="1" Type="HTML" WebPartZoneID="Main" DisplayName="$Resources:core,All_Tasks;" DefaultView="TRUE" MobileView="True" MobileDefaultView="False" ToolbarTemplate="myToolBarID” SetupPath="pages\viewpage.aspx" ImageUrl="/_layouts/images/issues.png" Url="AllItems.aspx>

Step 5: Build the custom form library definition and deploy it/

Step 6: Create a forms library based on this newly created definition.

Step 7: Toolbar for the newly created forms library will be missing.

Step 8: Save following code snippet as MyCustomFormLibToolBar.ascx into c:\Program Files\Common Files\Microsoft Shared\Web Service Extensions\12\Templates\CONTROLTEMPLATES

<%@ Control Language="C#" AutoEventWireup="false" %>

<%@Assembly Name="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

<%@Register TagPrefix="SharePoint" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" namespace="Microsoft.SharePoint.WebControls"%>

<%@Register TagPrefix="SPHttpUtility" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" namespace="Microsoft.SharePoint.Utilities"%>

<%@ Register TagPrefix="wssuc" TagName="ToolBar" src="~/_controltemplates/ToolBar.ascx" %>

<%@ Register TagPrefix="wssuc" TagName="ToolBarButton" src="~/_controltemplates/ToolBarButton.ascx" %>

<SharePoint:RenderingTemplate ID="myToolBarID" runat="server">

<Template>

<wssuc:ToolBar CssClass="ms-menutoolbar" EnableViewState="false" id="toolBarTbl" ButtonSeparator="''" RightButtonSeparator=" " runat="server">

<Template_Buttons>

<SharePoint:NewMenu AccessKey="<%$Resources:wss,tb_NewMenu_AK%>" runat="server"/>

<SharePoint:ActionsMenu AccessKey="<%$Resources:wss,tb_ActionsMenu_AK%>" runat="server"/>

<SharePoint:SettingsMenu AccessKey="<%$Resources:wss,tb_SettingsMenu_AK%>" runat="server"/>

</Template_Buttons>

<Template_RightButtons>

<SharePoint :PagingButton runat="server"/>

<SharePoint:ListViewSelector runat="server"/>

</Template_RightButtons>

</wssuc:ToolBar>

</Template>

</SharePoint:RenderingTemplate>


Step 9: IISReset

Step 10: Toolbar for the newly created Forms library is available.

Step 11: Open Advance Settings for the Forms Library settings

Step 12: Check Allow multiple content types, Open as Web Page.

Step 13: Select Add existing content type, and add “MyCustomContentType”.

The similar ascx control can be used to hide or remove toolbar buttons on specific SharePoint List, Document Library as well.