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

Toronto Stock Exchange (TSE) Stock Quote Sharepoint Web Part

August 26th, 2008 . by <Patrick/>

The Stock Quote Web Part is a custom web part that displays stock information from Yahoo Finance. It allows users to lookup stocks on either the TSE or NYSE

Click here to dowload the Web Part 

�


Minimal Sharepoint Application Page Code

July 26th, 2008 . by <Patrick/>

Below is some code to get you started on creating your own Sharepoint Application Page so that it looks just like the built in ones!

<%@ Assembly Name=”Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c”%>
<%@ Assembly Name=”CheckInAll, Version=1.0.0.0, Culture=neutral, PublicKeyToken=70b886b56e89f448″  %>
<%@ Page Language=”VB” MasterPageFile=”~/_layouts/application.master” Inherits=”VSeWSS.CheckInAll.CheckIn” %>
<asp:Content ID=”PageTitle” contentplaceholderid=”PlaceHolderPageTitle” runat=”server”>
 Check-In: All Documents
</asp:Content>

<asp:Content ID=”PageTitleInTitleArea” runat=”server”
             contentplaceholderid=”PlaceHolderPageTitleInTitleArea” >
 Check-In: All Documents
</asp:Content>

<asp:Content ID=”Main” contentplaceholderid=”PlaceHolderMain” runat=”server”>
<table>
<tr>
  <td class=”ms-descriptiontext” valign=”top”>
    <table border=”0″ cellpadding=”1″ cellspacing=”0″ width=”100%”>
     <tr>
      <td class=”ms-sectionheader” style=”padding-top: 4px;” height=”22″ valign=”top”>
        <H3 class=”ms-standardheader”>
                                Check-In Document
         </H3>

      </td>
     </tr>

     <tr>
      <td class=”ms-descriptiontext ms-inputformdescription”>
      �
                   Add comments to all the documents you are checking in
 �
      </td>
      <td><IMG SRC=”/_layouts/images/blank.gif” width=8 height=1 alt=”"></td>
     </tr>

     <tr>
      <td><IMG SRC=”/_layouts/images/blank.gif” width=150 height=19 alt=”"></td>
     </tr>

    </table>
   </td>
   <td class=”ms-authoringcontrols ms-inputformcontrols” valign=”top”
   align=”left” >
    <table border=”0″ width=”100%” cellspacing=”0″ cellpadding=”0″>
     <tr>

      <td width=”9px”><IMG SRC=”/_layouts/images/blank.gif” width=9 height=7 alt=”"></td>

      <td><IMG SRC=”/_layouts/images/blank.gif” width=150 height=7 alt=”"></td>

      <td width=”10px”><IMG SRC=”/_layouts/images/blank.gif” width=10 height=1 alt=”"></td>

     </tr>
     <tr>
      <td />
      <td class=”ms-authoringcontrols”>
       <table class=”ms-authoringcontrols” border=”0″ width=”100%” cellspacing=”0″ cellpadding=”0″>
       �
  �
     <tr id=”ctl00_PlaceHolderMain_ctl01_ctl02_tablerow1″>
      <td class=”ms-authoringcontrols” colspan=”2″ nowrap>
       <label for=”ctl00_PlaceHolderMain_ctl01_ctl02_InputFile” id=”ctl00_PlaceHolderMain_ctl01_ctl02_LiteralLabelText”>Comments:</label>
      </td>
     </tr>
     <tr id=”ctl00_PlaceHolderMain_ctl01_ctl02_tablerow2″>
      <td><IMG SRC=”/_layouts/images/blank.gif” width=1 height=3 alt=”"></td>
     </tr>
     <!– End Right_Text –>
     <tr id=”ctl00_PlaceHolderMain_ctl01_ctl02_tablerow3″>
      <td width=”11″ ><IMG SRC=”/_layouts/images/blank.gif” width=11 height=1 alt=”"></td>
      <td class=”ms-authoringcontrols” width=”99%”>
      �
                      <TABLE class=”ms-authoringcontrols” width=”100%”>
                    <TR><TD>
                      <SPAN dir=”ltr”>
                      <asp:TextBox runat=”server” Width=”350px” ID=”txtComments” TextMode=”MultiLine” Rows=”5″></asp:TextBox>
                      </SPAN>
                    </TD></TR>
                    </TABLE>
  �
      </td>
     </tr>
    �
     <tr id=”ctl00_PlaceHolderMain_ctl01_ctl02_tablerow5″>
      <td><IMG SRC=”/_layouts/images/blank.gif” width=1 height=6 alt=”"></td>
     </tr>
       </table>
      </td>
      <td width=”10px”><IMG SRC=”/_layouts/images/blank.gif” width=10 height=1 alt=”"></td>
     </tr>

     <tr>
      <td />
      <td><IMG SRC=”/_layouts/images/blank.gif” width=150 height=13 alt=”"></td>
      <td />
     </tr>

    </table>
   </td>
  </tr>
�
  <tr>
   <td height=”2px” class=”ms-sectionline” colspan=”2″>
   <IMG SRC=”/_layouts/images/blank.gif” width=1 height=1 alt=”">
   </td>
  </tr>
 �
  <tr>
   <td height=”10px” class=”ms-descriptiontext” colspan=”2″>
   <IMG SRC=”/_layouts/images/blank.gif” width=1 height=10 alt=”">
   </td>
  </tr>
  <tr>
   <td colspan=”2″>
    <table cellpadding=”0″ cellspacing=”0″ width=”100%”>
     <colgroup>
      <col width=”99%”>
      <col width=”1%”>
     </colgroup>
     <tr>
      <td>
        </td>
      <td nowrap>
       <asp:Button ID=”btnOK” Text=”OK” Width=”100px” runat=”server” />
       <asp:Button ID=”btnCancel” OnClientClick =”window.location=history.back();” Width=”100px” Text=”Cancel” runat=”server” />
      </td>
     </tr>
    </table>
   </td>
  </tr>
 �
  <tr>
   <td height=”40″ class=”ms-descriptiontext” colspan=”2″>
   <IMG SRC=”/_layouts/images/blank.gif” width=1 height=4 alt=”">
   </td>�
     </tr>
   �
  </td>
 </table>
</asp:Content>


Using the Sharepoint SPSiteMapProvider to Populate a TreeView Control

June 25th, 2008 . by <Patrick/>

Here’s a very simple way to populate a TreeView Control using the SPSiteMapProvider.

Just copy the code below, create an aspx page, name it what you want and then copy it to

C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS

 

Tree View 

 

Code for the application page:

<%@ Assembly Name=”Microsoft.SharePoint.ApplicationPages, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c”%>
<%@ Page language=”C#” MasterPageFile=”~/_layouts/application.master” %>
<%@ Import Namespace=”Microsoft.SharePoint.ApplicationPages” %>
<%@ Register Tagprefix=”SharePoint” Namespace=”Microsoft.SharePoint.WebControls” Assembly=”Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c” %>
<%@ Register Tagprefix=”Utilities” Namespace=”Microsoft.SharePoint.Utilities” 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=”wssawc” Namespace=”Microsoft.SharePoint.WebControls” Assembly=”Microsoft.SharePoint, 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=”wssuc” TagName=”ButtonSection” src=”~/_controltemplates/ButtonSection.ascx” mce_src=”~/_controltemplates/ButtonSection.ascx” %>
<%@ Import Namespace=”Microsoft.SharePoint” %>
<%@ Import Namespace=”Microsoft.SharePoint.Navigation” %>
<%@ Import Namespace=”System.Net” %>
<asp:Content ID=”Content1″ ContentPlaceHolderId=”PlaceHolderPageTitle” runat=”server”>
<asp:Literal id=”PageTitleLabel1″ runat=”server” ></asp:Literal>
</asp:Content>
<asp:Content ID=”Content2″ ContentPlaceHolderId=”PlaceHolderPageTitleInTitleArea” runat=”server”>
<asp:Label id=”PageTitleLabel” runat=”server” ></asp:Label>
</asp:Content>
<asp:Content ID=”Content3″ ContentPlaceHolderId=”PlaceHolderAdditionalPageHead” runat=”server”>
<script runat=”server”>
    void Page_Load(object sender, System.EventArgs e)
    {
           SPSiteMapProvider sitemapProvider = (SPSiteMapProvider)SiteMap.Providers[”SPSiteMapProvider”];
           SiteMapDataSource datasource = new SiteMapDataSource();
           datasource.Provider = sitemapProvider;
           this.TreeView1.DataSource = datasource;
           this.TreeView1.ExpandDepth = 1;
           this.TreeView1.DataBind();
    }

</script>
</asp:Content>
<asp:Content ID=”Content4″ ContentPlaceHolderId=”PlaceHolderPageImage” runat=”server”>
<img src=”/_layouts/images/blank.gif” mce_src=”/_layouts/images/blank.gif” width=1 height=1 alt=”" />
</asp:Content>
<asp:Content ID=”Content5″ ContentPlaceHolderId=”PlaceHolderPageDescription” runat=”server”>
  �
    <table cellpadding=”2″ cellspacing=”1″ width=”100%” class=”ms-informationbar” style=”margin-bottom: 5px;” border=0>
                <tr>
                    <td width=”10″ valign=”middle” style=”padding: 4px”>
                        <img id=”Img1″ src=”/_layouts/images/exclaim.gif” mce_src=”/_layouts/images/exclaim.gif” alt=”<%$Resources:wss,exclaim_icon%>” runat=”server”/>
                    </td>
                    <td class=”ms-descriptiontext”>
                        <SharePoint:EncodedLiteral ID=”EncodedLiteral1″ runat=”server” text=”Please select the site you wish to visit” EncodeMethod=’HtmlEncode’/>
                    </td>
                </tr>
              �
            </table>

    <asp:PlaceHolder id=”PublishDescription” Visible=”true” runat=”server”>
    <tr>
        <TD height=”8px”><img src=”/_layouts/images/blank.gif” mce_src=”/_layouts/images/blank.gif” width=”1″ height=”8″ alt=”"></td>
    </tr>
  �
    <tr>
      �
        <td colspan=”2″>
          �
            <table width=”100%”>
                <tr>
                    <td class=”ms-formbody”>
                        <asp:TreeView�
                            ID=”TreeView1″
                            ExpandDepth=”3″
                            Font-Names= “Arial”
                            Font-Size=”10pt”
                            ForeColor=”Blue”
                            NodeWrap=”true”
                            runat=”server”
                            >
                        </asp:treeview>
                    </td>
                </tr>
            </table>
        </td>
    </tr>
    </asp:PlaceHolder>
</asp:Content>

Â


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