Pat’s .Net and Sharepoint Blog
In the Microsoft Sharepoint and .Net Trenches

Cascading DropDownList Custom Field Control

May 28th, 2008 . by <Patrick/>

After reading the DataCogs article on Sharepoint – Cascading Drop Down Lists I was inspired to take the challenge and modify the code to allow for an infinite number of cascading drop downs. I learned alot from the article, and I would highly reccomend anyone trying to create their own custom fields in Sharepoint to read it. The current code has a parent child relationship however you cannot include a grandchild dropdown.

In my humble solution, I have a drop down of continents, then a related drop down for countries and then a third dropdown with the related cities.

Continents

I created three lists: 

Continents

Countries
Countries

Cities

Cities

Cities

Then I created a new list where I add the three custom field type Cascading DropDown Fields to the list

Add Field

 country

 city

I added three new fields to the Cascading DropDown List Details section.

Name - the name of the field this should be a unique name to identify the field

Parent Name - name of the parent DropDown list control if there is one

Child Name - name of the child DropDown list control if there is one

The first custom field I added was the Continent and named it MyContinent for a
lack of a better name and I set the child to be MyCountry

The second custom field I added was the Country and named it MyCountry and added
MyContinent as the parent and MyCity as the child

The third custome field I added was the City and named it MyCity and added MyCountry
as the parent and left the child blank

Once my list was configured, I was on my way to the races.

The code available for download below is part of a Sharepoint solution.

In order to install it on your Sharepoint installation open up a command prompt,
navigate to the Solution folder wherever you unzipped the code to and run the Install.bat
file. I have also included an Uninstall.bat file. I haven’t quite had enough
time yet to get it to work as a feature but I plan to in the weeks ahead. Before running the solution make sure you have the makecab.exe utility. The Microsoft Cabinet Software Development Kit can be downloaded here.

Download code

For references on how to package up solutions the following are good articles to read:

Patrick Tisseghem’s Development Tools and Techniques for Working with Code in Windows SharePoint Services 3.0 

Scot Hillier’s What’s Your Process for Developing SharePoint Features and Solutions? 

 

 

Read the rest of this entry »


SuperGrid

May 27th, 2008 . by <Patrick/>

Extending the GridView Control The SuperGrid control is an extended version of the ASP.Net GridView Control with some extra features. These features include the following:

  • An option to create a checkbox column and you can use the selectedIndexes property to obtain the selected values
  • A sorting indicator up/down
  • An automatic row count ie 1-10 of 200
  • Custom navigation
  • Row highlighting of any selected rows

I have included a Visual Studio 2005 Solution below along with a SQL Server database backup file that you can restore. I used the code from Dino Esposito’s wonder ful article in MSDN Magazine Extending the GridView Control as a starting point.

The solution includes two projects the SuperGrid which is basically the control and a little web application that makes use of the SuperGrid. The SuperGridSampleApp project includes a folder named db and this folder contains the database backup file called Customers.bak. The project also contains a folder named bll and it is an example on how I would typically create a business layer. I am curious about what other developers think about this technique of building a business layer.

Here is a screenshot of what it looks like:

SuperGrid

Click here to download a zip file with the code


Adding Sharepoint Intellisence to Visual Studio 2005

May 26th, 2008 . by <Patrick/>

Instead of adding the Sharepoint XML schema one file at a time to create your feature.xml files and element manifest files you can also add it to the Visual Studio XML schema cache. Every time Visual Studio loads, it loads the schemas defined in the XML schema cache automatically. 

Steps :

Navigate to:
c:\Program Files\Microsoft Visual Studio 8\Xml\Schemas

Create a new XML file called Sharepoint.xml

Add the following code to the file:
<SchemaCatalog xmlns=”http://schemas.microsoft.com/xsd/catalog”>
  <Schema href=”file://%ProgramFiles%/Common Files/Microsoft Shared/web server extensions/12/TEMPLATE/XML/wss.xsd” targetNamespace=”http://schemas.microsoft.com/sharepoint/” />
</SchemaCatalog>

Save the file If Visual Studio is already open close it then re-open it. This will reload all the schemas files including the one you just added

Now try creating a new feature.xml file

Specify the sharepoint namespace for the feature.xml file

XML Schema 

Now the intellisense should work!

 XML Schema


Where did my solution go in Visual Studio 2005!?

May 20th, 2008 . by <Patrick/>

Not sure if you’ve had this problem but sometimes in Visual Studio 2005 I lose the solution in solution explorer. To fix this problem go into Tools -> Options -> (Make sure Show all settings is checked) Projects and Solutions -> General and make sure that the “Always show Solution” is checked.

 Show Solution

 


Inserting Line breaks in a Sharepoint Data View Column

April 26th, 2008 . by <Patrick/>

Sometimes you want to fomat your Data View columns in a special way but Sharepoint Designer dissapoints you. The answer is to get dirty and modify the XSL in the Code behind the Data View web part.

I had a requirement to display a delimitted string comming from a column on multiple lines something like this:

Name Description URLS
Patrick Web Monkey http://www.microsoft.com
http://www.12thwave.com
http://blog.12thwave.com/

In the list the URL column was a pipe delimitted string (from Infopath) that looked like this:

http://www.microsoft.com%7chttp//www.12thwave.com%7Chttp://blog.12thwave.com

There are several XPath functions that could be used but unfortunately Sharepoint only supports XPath version 1.0 and all the good functions are in version 2.0 like tokenize() and split()

At first I tried the following technique (creating an xml file and adding it as a secondary data connection but for some reasone it did not like the hyperlinks I had) see: Inserting line breaks into text using Rules 

 

I came across an excellent site that provided me with a bunch of great xsl string functions where I found the solution:

http://www.dpawson.co.uk/xsl/sect2/N7240.html#d11074e349

Create a data view and use the following template
<xsl:template name=”links”>
  <xsl:param name=”str”/>
  <xsl:choose>
    <xsl:when test=”contains($str,’|')”>
      <a href=”{substring-before($str,’|')}” mce_href=”{substring-before($str,’|')}”><xsl:value-of
select=”substring-before($str,’|')”/></a>
      <xsl:text> </xsl:text><br/>
      <xsl:call-template name=”links”>
        <xsl:with-param name=”str” select=”substring-after($str,’|')”/>
      </xsl:call-template>
    </xsl:when>
    <xsl:otherwise>
      <a href=”{$str}” mce_href=”{$str}”><xsl:value-of select=”$str”/></a>
      <xsl:text> </xsl:text><br/>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>
Then output your URL field like so:
<td>
 <xsl:call-template name=”links”>
 <xsl:with-param name=”str” select=”substring-after(@URL, ‘, ‘)” />
 </xsl:call-template>
</td>
 


Custom Action Feature is installed but why don’t I see it??!!

March 26th, 2008 . by <Patrick/>

I created a custom action that is supposed to show up in the Actions drop down of a document library but it’s not.

Here’s my code:

 <?xml version=”1.0″ encoding=”utf-8″?>
<Elements Id=”745bc8db-3859-49fc-ac9d-4ebf74e1929e” xmlns=”http://schemas.microsoft.com/sharepoint/”>
  <CustomAction
  Id=”CheckInAll”
  RegistrationType=”List”
  RegistrationId=”101″
  GroupId=”ActionsMenu”
  Location=”Microsoft.Sharepoint.StandardMenu”
  ImageUrl=”~site/_layouts/images/checkin.GIF”
  Sequence=”1000″
  Title=”Check In All Documents” >
    <UrlAction Url=”~site/_layouts/CheckInAll.aspx?ListId={ListId}”/>
  </CustomAction>
</Elements>

Here’s the code that worked:

<?xml version=”1.0″ encoding=”utf-8″?>
<Elements Id=”745bc8db-3859-49fc-ac9d-4ebf74e1929e” xmlns=”http://schemas.microsoft.com/sharepoint/”>
  <CustomAction
  Id=”CheckInAll”
  RegistrationType=”List”
  RegistrationId=”101″
  GroupId=”ActionsMenu”
  Location=”Microsoft.SharePoint.StandardMenu”
  ImageUrl=”~site/_layouts/images/checkin.GIF”
  Sequence=”1000″
  Title=”Check In All Documents” >
    <UrlAction Url=”~site/_layouts/CheckInAll.aspx?ListId={ListId}”/>
  </CustomAction>
</Elements>

Can you spot the difference? Hint: the letter P


Creating a Custom Action and Custom Sharepoint Application Page using VSEWSS 1.1

February 26th, 2008 . by <Patrick/>

I love the deploy functionality built in to Visual Studio Extensions for Windows Sharepoint Services. It makes creating solution files so much easier. Creating manifest.xml files, using makecab.exe blah blah blah - what a headache! With every blog out there someone has a different way of creating it ie using ms build some third party tool from CodePlex, using .bat and .cmd files - Brutal!!

Anyways all was fine and dany I was pumping out webparts, lists, custom fields etc but then I tried deploying a custom application page and a custom action.

I created the following folder structure Template/Layouts/CustomAppPage and then put my .aspx file there but when deploying the solution VS was not copying the file to the 12 hive Layouts directory. When I checked out the WSP view my features and files were not there.

After a long time I finally realized what I was doing wrong. I first created my aspx file, feature and elements files in one project and then just copied them and added them to my new Empty Sharepoint solution.

What you need to always do is in Solution Explorer right click and then Add Item

For Application pages use the Template item for Elements.xml files use the Module item. Have Visual Studio create the files and then just copy and paste your existing code into them.

Now you should see your features in WSP view. Hit F2 to rename the the features and elements appropriately.


Minimal Masterpage

February 26th, 2008 . by <Patrick/>

<%– Identifies this page as a .master page written in C# and registers
tag prefixes, namespaces, assemblies and controls. –%>
<%@ Master language=”C#” %>
<!DOCTYPE html PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”
“http://www.w3.org/TR/html4/loose.dtd”>
<%@ Import Namespace=”Microsoft.SharePoint” %>
<%@ Register Tagprefix=”SPSWC” Namespace=”Microsoft.SharePoint.Portal.WebControls” Assembly=”Microsoft.SharePoint.Portal, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c” %>
<%@ Register Tagprefix=”SharePoint” Namespace=”Microsoft.SharePoint.WebControls” Assembly=”Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c” %>
<%@ Register Tagprefix=”WebPartPages” Namespace=”Microsoft.SharePoint.WebPartPages” Assembly=”Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c” %>
<%@ Register Tagprefix=”PublishingWebControls” Namespace=”Microsoft.SharePoint.Publishing.WebControls” Assembly=”Microsoft.SharePoint.Publishing, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c” %>
<%@ Register Tagprefix=”PublishingNavigation” Namespace=”Microsoft.SharePoint.Publishing.Navigation” Assembly=”Microsoft.SharePoint.Publishing, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c” %>
<%@ Register TagPrefix=”wssuc” TagName=”Welcome” src=”~/_controltemplates/Welcome.ascx” mce_src=”~/_controltemplates/Welcome.ascx” %>
<%@ Register TagPrefix=”wssuc” TagName=”DesignModeConsole” src=”~/_controltemplates/DesignModeConsole.ascx” mce_src=”~/_controltemplates/DesignModeConsole.ascx” %>
<%@ Register TagPrefix=”PublishingVariations” TagName=”VariationsLabelMenu” src=”~/_controltemplates/VariationsLabelMenu.ascx” mce_src=”~/_controltemplates/VariationsLabelMenu.ascx” %>
<%@ Register Tagprefix=”PublishingConsole” TagName=”Console” src=”~/_controltemplates/PublishingConsole.ascx” mce_src=”~/_controltemplates/PublishingConsole.ascx” %>
<%@ Register TagPrefix=”PublishingSiteAction” TagName=”SiteActionMenu” src=”~/_controltemplates/PublishingActionMenu.ascx” mce_src=”~/_controltemplates/PublishingActionMenu.ascx” %>
<%– Uses the Microsoft Office namespace and schema. –%>
<html>
  <SharePoint:RobotsMetaTag runat=”server”/>
  <%– The head section includes a content placeholder for the page
  title and links to CSS and JavaScript files that run on the server. –%>
  <head runat=”server”>
    <asp:ContentPlaceHolder runat=”server” id=”head”>
  <title>
        <asp:ContentPlaceHolder id=”PlaceHolderPageTitle” runat=”server” />
      </title>
    </asp:ContentPlaceHolder>
    <Sharepoint:CssLink runat=”server”/>
    <asp:ContentPlaceHolder id=”PlaceHolderAdditionalPageHead” runat=”server” />
  </head>
  <body onload=”javascript:_spBodyOnLoadWrapper();”>
  �
    <form runat=”server” onsubmit=”return _spFormOnSubmitWrapper();”>
   �
     <WebPartPages:SPWebPartManager runat=”server”/>
      <wssuc:Welcome id=”explitLogout” runat=”server”/>
      <PublishingSiteAction:SiteActionMenu runat=”server”/>
      <PublishingWebControls:AuthoringContainer id=”authoringcontrols”  runat=”server”>
      <PublishingConsole:Console runat=”server” />
      </PublishingWebControls:AuthoringContainer>
    �
   �
      <asp:ContentPlaceHolder id=”PlaceHolderMain” runat=”server” />
      <asp:Panel visible=”false” runat=”server”>
        <asp:ContentPlaceHolder id=”PlaceHolderSearchArea” runat=”server”/>
        <asp:ContentPlaceHolder id=”PlaceHolderTitleBreadcrumb” runat=”server”/>
        <asp:ContentPlaceHolder id=”PlaceHolderPageTitleInTitleArea” runat=”server”/>
        <asp:ContentPlaceHolder id=”PlaceHolderLeftNavBar” runat=”server”/>
        <asp:ContentPlaceHolder ID=”PlaceHolderPageImage” runat=”server”/>
        <asp:ContentPlaceHolder ID=”PlaceHolderBodyLeftBorder” runat=”server”/>
        <asp:ContentPlaceHolder ID=”PlaceHolderNavSpacer” runat=”server”/>
        <asp:ContentPlaceHolder ID=”PlaceHolderTitleLeftBorder” runat=”server”/>
        <asp:ContentPlaceHolder ID=”PlaceHolderTitleAreaSeparator” runat=”server”/>
        <asp:ContentPlaceHolder ID=”PlaceHolderMiniConsole” runat=”server”/>
        <asp:ContentPlaceHolder id=”PlaceHolderCalendarNavigator” runat =”server” />
        <asp:ContentPlaceHolder id=”PlaceHolderLeftActions” runat =”server”/>
        <asp:ContentPlaceHolder id=”PlaceHolderPageDescription” runat =”server”/>
        <asp:ContentPlaceHolder id=”PlaceHolderBodyAreaClass” runat =”server”/>
        <asp:ContentPlaceHolder id=”PlaceHolderTitleAreaClass” runat =”server”/>
       </asp:Panel>
    </form>
  </body>
</html>


Printing Column Headings on every page using a Data View in Sharepoint Designer

January 26th, 2008 . by <Patrick/>

If you want to print column headings on every page when you create a data view using Sharepoint Designer make sure you use the following Css in the code view of your page:

thead
{
   display:table-header-group;

add <thead> before <tr> tag


    Next Entries »