1
votes

I am trying to change the hyperlink on the AllItems.aspx page to point to a custom upload page for my document library called CustomUpload.aspx.

Assuming I have two Document Libraries (lists). One called vsList, created in Visual Studio and deployed as part of a SharePoint solution and the other called sdList, created the usual way from the browser.

Here's what I've been able to successfully accomplish to date:

  1. Edit the AllItems.aspx page of the sdList in the web based editor. Customize the XsltListViewWebPart that contains the "Add new item" hyperlink by setting it's Toolbar Type to "Summary". Then, using SharePoint Designer (SPD), I click the "Add new item" hyperlink in the designer view and the little right arrow appears and allows me to edit the hyperlink options (i.e. set the value to my own custom URL).
  2. Copy and paste the XSL code from above into the AllItems.aspx file for the vsList doc library and make sure that the path to the url is correct since of course SharePoint can never find anything because of the crapfest of mapped and virtual directories that "is" SharePoint.

Option #1 isn't a real solution because it only works for doc libraries that are created directly via the web-based GUI editor in the SP portal. I need to have all of this defined in my list definition that I created in VS. As for option #2, the issue is pretty much the same. If I copy and paste the custom XSL into the AllItems.aspx page then it will be overwritten each time I redeploy my VS solution that contains my custom list definition. So really I need a solution that will allow me to define the custom URL in my VS list definition.

Here's what SHOULD work -but doesn't:

  1. Create a custom Xsl file with all the tweaks required to override the default "Add new item" link. Edit the XslLink property of the XsltListViewWebPart in the AllItems.aspx page for the sdList document library by using Site Action => Edit Page => Edit Web Part => Miscellaneous => XSL Link.
  2. Edit the Elements.xml file for the list definition by adding the necessary Module and File XML tags to point to the custom XSL file that would override the "Add new item" URL. No matter what I do it won't deploy when I add in the tags because it just can't find the custom XSL file.

I've tried putting the file in like 100 different places and it keeps trying to look for it in "Features[MY PROJECT NAME]_PrimaryFeature\CustomStyle.xsl". Where does it get the idea that I'm storing the file in that path/location? Even when I try to store the XSL file in the SharePoint mapped LAYOUTS/XSL directory or in the Style Library document library in the actual SharePoint site it still can't find it. It's just maddening. Paths, location, directory structure and XSL have become the biggest roadblocks for me in trying to get anything done in SharePoint.

Please help.

1

1 Answers

1
votes

So here's what I ended up doing...

I basically perform steps 1 & 2 above in my original attempt and exported the entire site template to a local file on my workstation. Then I created a new SharePoint project/solution in Visual Studio (so as to not mess up my existing one), opted to import data from an existing site template and selected just the sdList to import into my new solution.

After the import process completed I was then able to look at the source that was generated for the AllItem.aspx (which contained the XSL code that I had manually updated using SPD) and then just copied that code to the Schema.xml file for the vsList in my existing SharePoint solution.

In the View section of the Schema.xml file I added the tag after the tag for BaseViewID #1 (i.e. the AllItems.aspx view) and pasted the code right there.

In an ideal situation I would have preferred to just dump all of the Xsl code in an external file and then just use the tag but I couldn't get that to work. For some reason SharePoint just can't find the file. This is one of my pet peeves with SharePoint (as noted in my original post): folder mapping and file locations. Unnecessarily confusing.

For those interested, here's what the custom Xsl looks like. Look for the line with "CustomUpload.aspx" as well as the lines immediately before and after it. Unfortunately I can't bold or highlight sections of code in this editor so you'll have to do a little sleuthing on your own.

    <Xsl>
          <![CDATA[
              <xsl:stylesheet xmlns:x="http://www.w3.org/2001/XMLSchema" xmlns:d="http://schemas.microsoft.com/sharepoint/dsp" version="1.0" exclude-result-prefixes="xsl msxsl ddwrt" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" xmlns:asp="http://schemas.microsoft.com/ASPNET/20" xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:SharePoint="Microsoft.SharePoint.WebControls" xmlns:ddwrt2="urn:frontpage:internal" xmlns:o="urn:schemas-microsoft-com:office:office"> 
  <xsl:include href="/_layouts/xsl/main.xsl"/> 
  <xsl:include href="/_layouts/xsl/internal.xsl"/> 
            <xsl:param name="AllRows" select="/dsQueryResponse/Rows/Row[$EntityName = '' or (position() &gt;= $FirstRow and position() &lt;= $LastRow)]"/>
            <xsl:param name="dvt_apos">&apos;</xsl:param>
            <xsl:template name="Freeform" ddwrt:ghost="" xmlns:ddwrt2="urn:frontpage:internal">
                <xsl:param name="AddNewText"/>
                <xsl:param name="ID"/>
                <xsl:variable name="Url">
                    <xsl:choose>
                        <xsl:when test="List/@TemplateType='119'"><xsl:value-of select="$HttpVDir"/>/_layouts/CreateWebPage.aspx?List=<xsl:value-of select="$List"/>&amp;RootFolder=<xsl:value-of select="$XmlDefinition/List/@RootFolder"/></xsl:when>
                        <xsl:when test="$IsDocLib"><xsl:value-of select="$HttpVDir"/>/_layouts/Upload.aspx?List=<xsl:value-of select="$List"/>&amp;RootFolder=<xsl:value-of select="$XmlDefinition/List/@RootFolder"/></xsl:when>
                        <xsl:otherwise><xsl:value-of select="$ENCODED_FORM_NEW"/></xsl:otherwise>
                    </xsl:choose>
    </xsl:variable>
                <xsl:variable name="HeroStyle">
                    <xsl:choose>
                        <xsl:when test="Toolbar[@Type='Standard']">display:none</xsl:when>
                        <xsl:otherwise></xsl:otherwise>
                    </xsl:choose>
    </xsl:variable>
                <xsl:if test="$ListRight_AddListItems = '1' and (not($InlineEdit) or $IsDocLib)">
      <table id="Hero-{$WPQ}" width="100%" cellpadding="0" cellspacing="0" border="0" style="{$HeroStyle}">
        <tr>
          <td colspan="2" class="ms-partline">
            <img src="/_layouts/images/blank.gif" width="1" height="1" alt="" />
          </td>          
        </tr>
        <tr>
          <td class="ms-addnew" style="padding-bottom: 3px">
          <span style="height:10px;width:10px;position:relative;display:inline-block;overflow:hidden;" class="s4-clust"><img src="/_layouts/images/fgimg.png" alt="" style="left:-0px !important;top:-128px !important;position:absolute;"  /></span>
            <xsl:text disable-output-escaping="yes" ddwrt:nbsp-preserve="yes">&amp;nbsp;</xsl:text>
            <xsl:choose>
                <xsl:when test="List/@TemplateType = '115'">
              <a class="ms-addnew" id="{$ID}-{$WPQ}"
                 href="{$Url}"
                 onclick="javascript:NewItem2(event, &quot;{$Url}&quot;);javascript:return false;"
                 target="_self">
                <xsl:value-of select="$AddNewText" />
              </a>
            </xsl:when>
                <xsl:otherwise>
                       <xsl:variable name="CustomUrl">
                          ../../../_layouts/MyControls/CustomUpload.aspx?List=<xsl:value-of select="$List"/>
                       </xsl:variable>
                       <a href="{$CustomUrl}"><xsl:value-of select="$AddNewText" /></a>
                    </xsl:otherwise>
            </xsl:choose>
          </td>
        </tr>
        <tr>
          <td>
            <img src="/_layouts/images/blank.gif" width="1" height="5" alt="" />
          </td>
        </tr>
      </table>
                    <xsl:choose>
                        <xsl:when test="Toolbar[@Type='Standard']">
          <script type='text/javascript'>
            if (typeof(heroButtonWebPart<xsl:value-of select="$WPQ"/>) != &quot;undefined&quot;)
            {
                <xsl:value-of select="concat('  var eleHero = document.getElementById(&quot;Hero-', $WPQ, '&quot;);')"/>
                if (eleHero != null)
                    eleHero.style.display = &quot;&quot;;
            }
          </script>
        </xsl:when>
                        <xsl:otherwise>
        </xsl:otherwise>
                    </xsl:choose>
                    <xsl:if test="List/@TemplateType = '115'">
          <script type='text/javascript'>
            if (typeof(DefaultNewButtonWebPart<xsl:value-of select="$WPQ"/>) != &quot;undefined&quot;)
            {
                <xsl:value-of select="concat('  var eleLink = document.getElementById(&quot;', $ID, '-', $WPQ, '&quot;);')"/>
                if (eleLink != null)
                {
                    DefaultNewButtonWebPart<xsl:value-of select="$WPQ"/>(eleLink);
                }
            }
          </script>
      </xsl:if>
    </xsl:if>
  </xsl:template></xsl:stylesheet>
              ]]>
        </Xsl>

Anyhow, I hope this helps someone out.