SharePoint 2010: 'Add Documents' link in a Form Library redirects to 'Upload.aspx' and not 'FormServer.aspx'

Article ID: 2639050 - View products that this article applies to.
Expand all | Collapse all

Symptoms

Consider the following scenario:

In SharePoint Server 2010, you create a new forms library. Subsequently, you edit one of the views of the form library by modifying the XSLTListView web part by enabling either 'Asynchronous Automatic Refresh' or 'Show Manual Refresh' button. Once either of the AJAX options have been enabled on the web part and an asynchronous post back has been made, the 'Add Documents' link on the page will point to 'upload.aspx' instead of '_layouts/FormServer.aspx'.

Cause

This is expected behavior at the time of this article's creation.

Resolution

To resolve this issue, modify the XSL of the XSLTListView web part using any of the below methods.

Option 1

Using SharePoint Designer:

1) Open the site.
2) In Site Objects select Lists and Libraries > <Form Library>
3) Select the view that needs to be changed from the list of views.
4) On the Home tab of the Ribbon enable Advanced Mode.
5) Set SharePoint Designer to use split screen.
6) Select the XsltListViewWebPart in the design view.
7) In code view find </DataFields>
8) Paste the following after <DataFields>

<Xsl>
<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" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime">&amp;nbsp;</xsl:text>
              <xsl:choose>
                <xsl:when test="List/@TemplateType = '115'">
                  <xsl:variable name="myUrl">
                    <xsl:text disable-output-escaping="yes">$serverUrl/_layouts/FormServer.aspx?XsnLocation=$serverUrl/$libraryName/Forms/$templateName&amp;SaveLocation=$serverUrl/$libraryName&amp;ClientInstalled=false&amp;Source=$serverUrl/$libraryName/Forms/$pageName&amp;DefaultItemOpen=1</xsl:text>
                  </xsl:variable>
                  <a class="ms-addnew" id="{$ID}-{$WPQ}"
                     href="{$myUrl}"
                     onclick=""
                     target="_self">
                    <xsl:value-of select="$AddNewText" />
                  </a>
                </xsl:when>
                <xsl:otherwise>
                  <a class="ms-addnew" id="{$ID}"
                     href="{$Url}"
                     onclick="javascript:NewItem2(event, &quot;{$Url}&quot;);javascript:return false;"
                     target="_self">
                    <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:template name="View_Default_RootTemplate" mode="RootTemplate" match="View" ddwrt:dvt_mode="root" ddwrt:ghost="" xmlns:ddwrt2="urn:frontpage:internal">
      <xsl:param name="ShowSelectAllCheckbox" select="'True'"/>
      <xsl:if test="($IsGhosted = '0' and $MasterVersion=3 and Toolbar[@Type='Standard']) or $ShowAlways">
        <xsl:call-template name="ListViewToolbar"/>
      </xsl:if>
      <table width="100%" cellspacing="0" cellpadding="0" border="0">
        <xsl:if test="not($NoCTX)">
          <xsl:call-template name="CTXGeneration"/>
        </xsl:if>
        <xsl:if test="List/@TemplateType=109">
          <xsl:call-template name="PicLibScriptGeneration"/>
        </xsl:if>
        <tr>
          <td>
            <xsl:if test="not($NoAJAX)">
              <iframe src="javascript:false;" id="FilterIframe{$ViewCounter}" name="FilterIframe{$ViewCounter}" style="display:none" height="0" width="0" FilterLink="{$FilterLink}"></iframe>
            </xsl:if>
            <table summary="{List/@title} {List/@description}" o:WebQuerySourceHref="{$HttpPath}&amp;XMLDATA=1&amp;RowLimit=0&amp;View={$View}"
                            width="100%" border="0" cellspacing="0" dir="{List/@Direction}">
              <xsl:if test="not($NoCTX)">
                <xsl:attribute name="onmouseover">
                  EnsureSelectionHandler(event,this,<xsl:value-of select ="$ViewCounter"/>)
                </xsl:attribute>
              </xsl:if>
              <xsl:if test="$NoAJAX">
                <xsl:attribute name="FilterLink">
                  <xsl:value-of select="$FilterLink"/>
                </xsl:attribute>
              </xsl:if>
              <xsl:attribute name="cellpadding">
                <xsl:choose>
                  <xsl:when test="ViewStyle/@ID='15' or ViewStyle/@ID='16'">0</xsl:when>
                  <xsl:otherwise>1</xsl:otherwise>
                </xsl:choose>
              </xsl:attribute>
              <xsl:attribute name="id">
                <xsl:choose>
                  <xsl:when test="$IsDocLib or dvt_RowCount = 0">onetidDoclibViewTbl0</xsl:when>
                  <xsl:otherwise>
                    <xsl:value-of select="concat($List, '-', $View)"/>
                  </xsl:otherwise>
                </xsl:choose>
              </xsl:attribute>
              <xsl:attribute name="class">
                <xsl:choose>
                  <xsl:when test="ViewStyle/@ID='0' or ViewStyle/@ID='17'">
                    <xsl:value-of select="$ViewClassName"/> ms-basictable
                  </xsl:when>
                  <xsl:otherwise>
                    <xsl:value-of select="$ViewClassName"/>
                  </xsl:otherwise>
                </xsl:choose>
              </xsl:attribute>
              <xsl:if test="$InlineEdit">
                <xsl:attribute name="inlineedit">
                  javascript: <xsl:value-of select="ddwrt:GenFireServerEvent('__cancel;dvt_form_key={@ID}')"/>;CoreInvoke(&apos;ExpGroupOnPageLoad&apos;, &apos;true&apos;);
                </xsl:attribute>
              </xsl:if>
              <xsl:apply-templates select="." mode="full">
                <xsl:with-param name="ShowSelectAllCheckbox" select="$ShowSelectAllCheckbox"/>
              </xsl:apply-templates>
            </table>
            <xsl:choose>
              <xsl:when test="$IsDocLib or dvt_RowCount = 0">
                <script type='text/javascript'>HideListViewRows(&quot;onetidDoclibViewTbl0&quot;);</script>
              </xsl:when>
              <xsl:otherwise>
                <script type='text/javascript'>
                  <xsl:value-of select ="concat('HideListViewRows(&quot;', $List, '-', $View, '&quot;);')"/>
                </script>
              </xsl:otherwise>
            </xsl:choose>
          </td>
        </tr>
        <xsl:if test="$dvt_RowCount = 0 and not (@BaseViewID='3' and List/@TemplateType='102')">
          <tr>
            <td>
              <table width="100%" border="0" dir="{List/@Direction}">
                <xsl:call-template name="EmptyTemplate" />
              </table>
            </td>
          </tr>
        </xsl:if>
      </table>
      <xsl:call-template name="pagingButtons" />
      <xsl:if test="Toolbar[@Type='Freeform'] or ($MasterVersion=4 and Toolbar[@Type='Standard'])">
        <xsl:call-template name="Freeform">
          <xsl:with-param name="AddNewText">
            <xsl:choose>
              <xsl:when test="List/@TemplateType='104'">
                <xsl:value-of select="'Add new announcement'"/>
              </xsl:when>
              <xsl:when test="List/@TemplateType='101' or List/@TemplateType='115'">
                <xsl:value-of select="'Add document'"/>
              </xsl:when>
              <xsl:when test="List/@TemplateType='103'">
                <xsl:value-of select="'Add new link'"/>
              </xsl:when>
              <xsl:when test="List/@TemplateType='106'">
                <xsl:value-of select="'Add new event'"/>
              </xsl:when>
              <xsl:when test="List/@TemplateType='119'">
                <xsl:value-of select="'Add new page'"/>
              </xsl:when>
              <xsl:otherwise>
                <xsl:value-of select="'Add new item'"/>
              </xsl:otherwise>
            </xsl:choose>
          </xsl:with-param>
          <xsl:with-param name="ID">
            <xsl:choose>
              <xsl:when test="List/@TemplateType='104'">idHomePageNewAnnouncement</xsl:when>
              <xsl:when test="List/@TemplateType='101'">idHomePageNewDocument</xsl:when>
              <xsl:when test="List/@TemplateType='103'">idHomePageNewLink</xsl:when>
              <xsl:when test="List/@TemplateType='106'">idHomePageNewEvent</xsl:when>
              <xsl:when test="List/@TemplateType='119'">idHomePageNewWikiPage</xsl:when>
              <xsl:otherwise>idHomePageNewItem</xsl:otherwise>
            </xsl:choose>
          </xsl:with-param>
        </xsl:call-template>
      </xsl:if>
    </xsl:template>
  </xsl:stylesheet>
</Xsl>

9) Find the following line in the XSL:

<xsl:text disable-output-escaping="yes">$serverUrl/_layouts/FormServer.aspx?XsnLocation=$serverUrl/$libraryName/Forms/$templateName&amp;SaveLocation=$serverUrl/$libraryName&amp;ClientInstalled=false&amp;Source=$serverUrl/$libraryName/Forms/$pageName&amp;DefaultItemOpen=1</xsl:text>

10) Replace $serverUrl with the URL for the site including http://
11) Replace $libraryName with the name of the forms library
12) Replace $templateName with the name of the form template. The name of the form template can be determined by clicking the 'add document' link
 on view that does not have asynchronous refresh enabled and checking the query parameters.
13) Replace $pageName with the view file name. For example: 'AllItems.aspx'.
14) Save the page.


Option 2

Using the SharePoint 2010 Management Shell:

1) Create a new file with 'ps1' extension.
2) Paste the following into the newly created file.

PARAM(
[String]$ServerUrl = $null,
[String]$pageName =  $null,
[String]$libraryName = $null,
[String]$templateName = $null
)

$xsl = @("
  <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`" xmlns:ddwrt=`"http://schemas.microsoft.com/WebParts/v2/DataView/runtime`">&amp;nbsp;</xsl:text>
              <xsl:choose>
                <xsl:when test=`"List/@TemplateType = '115'`">
                  <xsl:variable name=`"myUrl`">
                    <xsl:text disable-output-escaping=`"yes`">$serverUrl/_layouts/FormServer.aspx?XsnLocation=$serverUrl/$libraryName/Forms/$templateName&amp;SaveLocation=$serverUrl/$libraryName&amp;ClientInstalled=false&amp;Source=$serverUrl/$libraryName/Forms/$pageName&amp;DefaultItemOpen=1</xsl:text>
                  </xsl:variable>
                  <a class=`"ms-addnew`" id=`"{`$ID}-{`$WPQ}`"
                     href=`"{`$myUrl}`"
                     onclick=`"`"
                     target=`"_self`">
                    <xsl:value-of select=`"`$AddNewText`" />
                  </a>
                </xsl:when>
                <xsl:otherwise>
                  <a class=`"ms-addnew`" id=`"{`$ID}`"
                     href=`"{`$Url}`"
                     onclick=`"javascript:NewItem2(event, &quot;{`$Url}&quot;);javascript:return false;`"
                     target=`"_self`">
                    <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:template name=`"View_Default_RootTemplate`" mode=`"RootTemplate`" match=`"View`" ddwrt:dvt_mode=`"root`" ddwrt:ghost=`"`" xmlns:ddwrt2=`"urn:frontpage:internal`">
      <xsl:param name=`"ShowSelectAllCheckbox`" select=`"'True'`"/>
      <xsl:if test=`"(`$IsGhosted = '0' and `$MasterVersion=3 and Toolbar[@Type='Standard']) or `$ShowAlways`">
        <xsl:call-template name=`"ListViewToolbar`"/>
      </xsl:if>
      <table width=`"100%`" cellspacing=`"0`" cellpadding=`"0`" border=`"0`">
        <xsl:if test=`"not(`$NoCTX)`">
          <xsl:call-template name=`"CTXGeneration`"/>
        </xsl:if>
        <xsl:if test=`"List/@TemplateType=109`">
          <xsl:call-template name=`"PicLibScriptGeneration`"/>
        </xsl:if>
        <tr>
          <td>
            <xsl:if test=`"not(`$NoAJAX)`">
              <iframe src=`"javascript:false;`" id=`"FilterIframe{`$ViewCounter}`" name=`"FilterIframe{`$ViewCounter}`" style=`"display:none`" height=`"0`" width=`"0`" FilterLink=`"{`$FilterLink}`"></iframe>
            </xsl:if>
            <table summary=`"{List/@title} {List/@description}`" o:WebQuerySourceHref=`"{`$HttpPath}&amp;XMLDATA=1&amp;RowLimit=0&amp;View={`$View}`"
                            width=`"100%`" border=`"0`" cellspacing=`"0`" dir=`"{List/@Direction}`">
              <xsl:if test=`"not(`$NoCTX)`">
                <xsl:attribute name=`"onmouseover`">
                  EnsureSelectionHandler(event,this,<xsl:value-of select =`"`$ViewCounter`"/>)
                </xsl:attribute>
              </xsl:if>
              <xsl:if test=`"`$NoAJAX`">
                <xsl:attribute name=`"FilterLink`">
                  <xsl:value-of select=`"`$FilterLink`"/>
                </xsl:attribute>
              </xsl:if>
              <xsl:attribute name=`"cellpadding`">
                <xsl:choose>
                  <xsl:when test=`"ViewStyle/@ID='15' or ViewStyle/@ID='16'`">0</xsl:when>
                  <xsl:otherwise>1</xsl:otherwise>
                </xsl:choose>
              </xsl:attribute>
              <xsl:attribute name=`"id`">
                <xsl:choose>
                  <xsl:when test=`"`$IsDocLib or dvt_RowCount = 0`">onetidDoclibViewTbl0</xsl:when>
                  <xsl:otherwise>
                    <xsl:value-of select=`"concat(`$List, '-', `$View)`"/>
                  </xsl:otherwise>
                </xsl:choose>
              </xsl:attribute>
              <xsl:attribute name=`"class`">
                <xsl:choose>
                  <xsl:when test=`"ViewStyle/@ID='0' or ViewStyle/@ID='17'`">
                    <xsl:value-of select=`"`$ViewClassName`"/> ms-basictable
                  </xsl:when>
                  <xsl:otherwise>
                    <xsl:value-of select=`"`$ViewClassName`"/>
                  </xsl:otherwise>
                </xsl:choose>
              </xsl:attribute>
              <xsl:if test=`"`$InlineEdit`">
                <xsl:attribute name=`"inlineedit`">
                  javascript: <xsl:value-of select=`"ddwrt:GenFireServerEvent('__cancel;dvt_form_key={@ID}')`"/>;CoreInvoke(&apos;ExpGroupOnPageLoad&apos;, &apos;true&apos;);
                </xsl:attribute>
              </xsl:if>
              <xsl:apply-templates select=`".`" mode=`"full`">
                <xsl:with-param name=`"ShowSelectAllCheckbox`" select=`"`$ShowSelectAllCheckbox`"/>
              </xsl:apply-templates>
            </table>
            <xsl:choose>
              <xsl:when test=`"`$IsDocLib or dvt_RowCount = 0`">
                <script type='text/javascript'>HideListViewRows(&quot;onetidDoclibViewTbl0&quot;);</script>
              </xsl:when>
              <xsl:otherwise>
                <script type='text/javascript'>
                  <xsl:value-of select =`"concat('HideListViewRows(&quot;', `$List, '-', `$View, '&quot;);')`"/>
                </script>
              </xsl:otherwise>
            </xsl:choose>
          </td>
        </tr>
        <xsl:if test=`"`$dvt_RowCount = 0 and not (@BaseViewID='3' and List/@TemplateType='102')`">
          <tr>
            <td>
              <table width=`"100%`" border=`"0`" dir=`"{List/@Direction}`">
                <xsl:call-template name=`"EmptyTemplate`" />
              </table>
            </td>
          </tr>
        </xsl:if>
      </table>
      <xsl:call-template name=`"pagingButtons`" />
      <xsl:if test=`"Toolbar[@Type='Freeform'] or (`$MasterVersion=4 and Toolbar[@Type='Standard'])`">
        <xsl:call-template name=`"Freeform`">
          <xsl:with-param name=`"AddNewText`">
            <xsl:choose>
              <xsl:when test=`"List/@TemplateType='104'`">
                <xsl:value-of select=`"'Add new announcement'`"/>
              </xsl:when>
              <xsl:when test=`"List/@TemplateType='101' or List/@TemplateType='115'`">
                <xsl:value-of select=`"'Add document'`"/>
              </xsl:when>
              <xsl:when test=`"List/@TemplateType='103'`">
                <xsl:value-of select=`"'Add new link'`"/>
              </xsl:when>
              <xsl:when test=`"List/@TemplateType='106'`">
                <xsl:value-of select=`"'Add new event'`"/>
              </xsl:when>
              <xsl:when test=`"List/@TemplateType='119'`">
                <xsl:value-of select=`"'Add new page'`"/>
              </xsl:when>
              <xsl:otherwise>
                <xsl:value-of select=`"'Add new item'`"/>
              </xsl:otherwise>
            </xsl:choose>
          </xsl:with-param>
          <xsl:with-param name=`"ID`">
            <xsl:choose>
              <xsl:when test=`"List/@TemplateType='104'`">idHomePageNewAnnouncement</xsl:when>
              <xsl:when test=`"List/@TemplateType='101'`">idHomePageNewDocument</xsl:when>
              <xsl:when test=`"List/@TemplateType='103'`">idHomePageNewLink</xsl:when>
              <xsl:when test=`"List/@TemplateType='106'`">idHomePageNewEvent</xsl:when>
              <xsl:when test=`"List/@TemplateType='119'`">idHomePageNewWikiPage</xsl:when>
              <xsl:otherwise>idHomePageNewItem</xsl:otherwise>
            </xsl:choose>
          </xsl:with-param>
        </xsl:call-template>
      </xsl:if>
    </xsl:template>
  </xsl:stylesheet>" 
)


if([String]::IsNullOrEmpty($ServerUrl) -and [String]::IsNullOrEmpty($libraryName) -and [String]::IsNullOrEmpty($templateName) -and [String]::IsNullOrEmpty($pageName))
{
 Echo "Not all the required parameters were provided"
}
else

 $web = get-spweb $serverUrl
 $list = $web.Lists[$libraryName]
 foreach($folder in $list.RootFolder.SubFolders.GetEnumerator())
 {
  foreach($file in $folder.Files.GetEnumerator())
  {
   if($file.Name.Equals($pageName))
   {
    $manager = $file.GetLimitedWebPartManager([Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)
    if ($manager.WebParts.Count -eq 1)
    {
     $webpart = $manager.WebParts[0]
     if($webpart.GetType().Name.Equals("XsltListViewWebPart"))
     {
      $webpart.set_Xsl($xsl)
      $manager.SaveChanges($webpart)
     }
    } 
   }
  }
 }
}

3.) Save the file.
4.) Run <name>.ps1 <serverUrl> <pageName> <libraryName> <templateName>

Replace the text within <> with the appropriate values.
Note This is a "FAST PUBLISH" article created directly from within the Microsoft support organization. The information contained herein is provided as-is in response to emerging issues. As a result of the speed in making it available, the materials may include typographical errors and may be revised at any time without notice. See Terms of Use for other considerations.

Properties

Article ID: 2639050 - Last Review: July 12, 2012 - Revision: 4.0
Applies to
  • Microsoft SharePoint Server 2010
  • Microsoft SharePoint Server 2010 Service Pack 1
Keywords: 
KB2639050

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com