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

XSLT Code to output a hyperlink column in Sharepoint Designer

December 11th, 2008 . by <Patrick/>
 

<td class=”ms-vb”>
    <a class=”ms-toolbar”>
              <xsl:attribute name=”href”>
              <xsl:text>/_layouts/FormServer.aspx?</xsl:text>
              <xsl:text>XmlLocation=</xsl:text>
              <xsl:value-of select=”@FileRef”></xsl:value-of>
              <xsl:text>&</xsl:text>
              <xsl:text>OpenIn=Client</xsl:text>�
              </xsl:attribute>
              <xsl:value-of select=”@FileLeafRef”></xsl:value-of>
         </a>
   </td>


Using a Replace Web Service in a Sharepoint Web Based InfoPath form

December 10th, 2008 . by <Patrick/>
Due to the lack of an easy way to do a find and replace in InfoPath, I developed a simple web service with a web method called replace that uses managed code to call the replace method of the string data type. Here’s how I call the web method in a browser-based Sharepoint InfoPath form.

First create a form like so..

With fields txtFind, txtReplace and txtText

The idea in this sample form is to replace mother with sister in the text “Don’t forget to call your mother today!”
The next thing you must to is create a new data connection.

You should first see if your Sharepoint server already has a data connection to the Replace web method

Enter the URL of the site like in the above image and then expand the data connections.

Select the Replace.udcx data connection. If you do not see this data connection you must create a new data connection to receive data and then select the web service

Once you have created the web service data connection you must convert it to a data connection file that you must store in a data connection library in your Sharepoint site.

Now you will be presented with the data connection wizard

The web method requires three parameters:

Text: the text you want to do the search and replace on
stringToFind: the text you want to replace ie mother
stringToReplace: the text you want to replace it to ie daughter
escapeSpaces: If you are having difficulty with spaces in your strings and need to use %20 then set this to true otherwise default it to false

For now don’t set default values and click on next, next deselect Automatically retrieve data when form is opened and then click on finish
Your data connection has now been created

So the next thing we need to do is create some rules for our button

The rule will have the following actions - set each of the parameters of the data connection , then query the data connection and then set the txtText value to the result of the data connection query

For the first rule we set the text parameter of the Replace datasource to the value of the txtText field. (make sure to select the Replace data source and not the main data source)

Then create the following actions so that it looks something like this:

Now test out your rule by previewing the form

Click on the Replace button and the text shoudl read Don’t forget to call your daughter today!

Here’s the code for my web method:

_
Public
Function Replace(ByVal text As String, ByVal stringToFind As String, ByVal stringToReplace As String, ByVal escapeSpaces As String) As String

If escapeSpaces.ToUpper = “TRUE” ThenstringToFind = stringToFind.Replace(” “, “%20″)

End If

Return text.Replace(stringToFind, stringToReplace)

End
Function
 


Replace XSLT Template for Sharepoint Designer

December 3rd, 2008 . by <Patrick/>

If you need to do a find and replace when outputting a column in a data view you can use the following:

<xsl:template name=”stringreplace”>
  <xsl:param name=”stringvalue” />
  <xsl:param name=”from” />
  <xsl:param name=”to” />
  <xsl:choose>
   <xsl:when test=”contains($stringvalue, $from)”><xsl:value-of select=”substring-before($stringvalue, $from)” />
    <xsl:if test=”contains(substring($stringvalue, 1, string-length($stringvalue) - 1), $from)”><xsl:value-of select=”$to” />
     <xsl:call-template name=”stringreplace”>
      <xsl:with-param name=”stringvalue” select=”substring-after($stringvalue, $from)” />
      <xsl:with-param name=”from” select=”$from” />
      <xsl:with-param name=”to” select=”$to” />
     </xsl:call-template>
    </xsl:if>
   </xsl:when>
   <xsl:otherwise><xsl:value-of select=”$stringvalue” /></xsl:otherwise>
  </xsl:choose>
 </xsl:template>

Call the template code:
Say you have a column named ColumnName and you want to replace all occurrences of True and set them to False…..

 <xsl:call-template name=”stringreplace”>
 <xsl:with-param name=”stringvalue” select=”@ColumnName” />
 <xsl:with-param name=”from” select=”True” />
 <xsl:with-param name=”to” select=”False” />
 </xsl:call-template>


Convert to XSLT Data View Sharepoint Designer Bug

December 2nd, 2008 . by <Patrick/>

After adding a list to a custom aspx page in designer you choose to Convert to an XSLT Data View you recieve the following error: This web part does not have a valid xslt stylesheet: Error a name was started with an invalid character.

The cause of the problem seems to be the following line:

<xsl:when test=”ddwrt:IfHasRights(4)”><a href=”{$URL_Edit}?ID={@ID}” mce_href=”{$URL_Edit}?ID={@ID}” onclick=”STSNavigateWithCheckoutAlert(this.href, ‘<xsl:choose><xsl:when test=” @CheckedOutUserId=”"><xsl:value-of select=”ddwrt:ListProperty(’ForceCheckout’)” /></a></xsl:when>
Basically if you remove the Edit (link to edit item) field before you do the conversion you should be all right. If you need the edit link then you will have to modify the edit link xslt manually using something like:

<TD Class=”{$IDALDA4G}”>
    <a href=”{$URL_Edit}?ID={@ID}” mce_href=”{$URL_Edit}?ID={@ID}&Source=http://ira07/Insurance%20and%20Risk%20Assessment/IRAInitiatives/Site%20Pages/Patrick.aspx”><img border=”0″ alt=”Edit Document Properties” src=”/_layouts/images/edititem.gif” mce_src=”/_layouts/images/edititem.gif” /></a>
</TD>

If you apply Source url querystring parameters when redirecting to an application page, the system will usually redirect to the source url querystring parameter after an action is performed on the application page.


Line feeds / Line breaks Sharepoint Dataviews

December 2nd, 2008 . by <Patrick/>

After having published an Infopath form with a rich textbox field to a document library, I created a dataview of the list.

The column that came from the rich textbox control (Comments) lost it’s linebreaks. In order to fix the problem I used the following code:

 <xsl:value-of select="ddwrt:AutoNewLine(string(@Comments))" disable-output-escaping="yes" />


Infopath Forms Services Form opens in browser but as XML

October 26th, 2008 . by <Patrick/>

When opening an infopath form the XML code appears in the browser.
Open Infopath go into Tools / Options
Check – Check whether Microsoft Office is the default program for opening and editing .xml files

Infopath Options


Updating Sharepoint 2003 Infopath Forms to 2007

September 26th, 2008 . by <Patrick/>

When you migrate a form library from Sharepoint 2003 to Sharepoint 2007 references to the Form template will still point to the 2003 form library.
If you need to update the reference Sharepoint has a relink documents feature to individually re-link the xml forms to the appropriate template.
Unfortunately this process can be rather cumbersome especially if the form library contains sub folders. To alleviate this painful process
I developed a tool that with go through an entire directory structure recursively and do a find and replace on the template (.XSN) file.
What you will need to do is go into the explorer view of the form library, copy all files and folders to a location on your local hard drive.
Then open up the “UpdateInfopathTemplate” utility and update all the xml forms. Then copy all the forms back to the destination form library in 2007.

Click here to download the utility


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>


« Previous Entries