Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I'm in a dataview (in Sharepoint Designer). I'm trying to display a link to an attachment of an Item from a custom list. I use that code :

               <xsl:element name="sharepoint:AttachmentsField">
                    <xsl:attribute name="runat">server</xsl:attribute>
                    <xsl:attribute name="FieldName">Attachments</xsl:attribute>
                    <xsl:attribute name="ControlMode">Display</xsl:attribute>
                    <xsl:attribute name="Visible">true</xsl:attribute>
                    <xsl:attribute name="ItemId">
                        <xsl:value-of select="@ID"/>
                    </xsl:attribute>
                </xsl:element>  

I get the following error : Type 'Microsoft.SharePoint.WebControls.AttachmentsField' does not have a public property named 'xmlns:sharepoint'. Here's all the XML for the dataview I'm using :

          <datafields>@Title,Title;@Body,Body;@Publishing_Date,Publishing Date;@Expires,Expires;@ShortDescription,Short Description;@Press_Release_Year,Year;@Item_x0020_Language,Item Language;@ID,ID;@ContentType,Content Type;@Modified,Modified;@Created,Created;@Author,Created By;@Editor,Modified By;@_UIVersionString,Version;@Attachments,Attachments;@File_x0020_Type,File Type;@FileLeafRef,Name (for use in forms);@FileDirRef,Path;@FSObjType,Item Type;@_HasCopyDestinations,Has Copy Destinations;@_CopySource,Copy Source;@ContentTypeId,Content Type ID;@_ModerationStatus,Approval Status;@_UIVersion,UI Version;@Created_x0020_Date,Created;@FileRef,URL Path;</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">
              <xsl:output method="html" indent="no"/>
              <xsl:decimal-format NaN=""/>
              <xsl:param name="dvt_apos">'</xsl:param>
              <xsl:param name="ListID">{E1BBFD8D-6052-477B-921D-A3055E69399B}</xsl:param>
              <xsl:param name="WebURL">{sitecollectionroot}</xsl:param>
              <xsl:param name="PR">1</xsl:param>
              <xsl:variable name="dvt_1_automode">0</xsl:variable>
              <xsl:template match="/">
                <xsl:call-template name="dvt_1"/>
              </xsl:template>
              <xsl:template name="dvt_1">
                <xsl:variable name="dvt_StyleName">Table</xsl:variable>
                <xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row"/>
                  <xsl:call-template name="dvt_1.body">
                    <xsl:with-param name="Rows" select="$Rows"/>
                  </xsl:call-template>
              </xsl:template>
              <xsl:template name="dvt_1.body">
                <xsl:param name="Rows"/>
                <xsl:for-each select="$Rows">
                  <xsl:call-template name="dvt_1.rowview"/>
                </xsl:for-each>
              </xsl:template>
              <xsl:template name="dvt_1.rowview">
                <div class="prItemTitle"><xsl:value-of select="ddwrt:FormatDateTime(string(@Publishing_Date) , 1036,'yyyy/MM/dd')" /> -  <xsl:value-of select="@Title"/></div>
                 <xsl:choose>
                    <xsl:when test="@Attachments='1' or msxsl:string-compare(string(@Attachments),'Yes','','i')=0 or msxsl:string-compare(string(@Attachments),'True','','i')=0"><xsl:value-of select="@Attachments" /></xsl:when>
                    <xsl:otherwise>
                    </xsl:otherwise>
                 </xsl:choose>
                <div class="prItemBody"><xsl:value-of select="@Body" disable-output-escaping="yes"/></div>

                <xsl:element name="sharepoint:AttachmentsField">
                    <xsl:attribute name="runat">server</xsl:attribute>
                    <xsl:attribute name="FieldName">Attachments</xsl:attribute>
                    <xsl:attribute name="ControlMode">Display</xsl:attribute>
                    <xsl:attribute name="Visible">true</xsl:attribute>
                    <xsl:attribute name="ItemId">
                        <xsl:value-of select="@ID"/>
                    </xsl:attribute>
                </xsl:element>                        

              </xsl:template>
            </xsl:stylesheet>
          </XSL>
          <parameterbindings>
            <ParameterBinding Name="dvt_apos" Location="Postback;Connection"/>
            <ParameterBinding Name="UserID" Location="CAMLVariable" DefaultValue="CurrentUserName"/>
            <ParameterBinding Name="Today" Location="CAMLVariable" DefaultValue="CurrentDate"/>
            <ParameterBinding Name="ListID" Location="None" DefaultValue="{E1BBFD8D-6052-477B-921D-A3055E69399B}"/>
            <ParameterBinding Name="WebURL" Location="None" DefaultValue="{sitecollectionroot}"/>
            <ParameterBinding Name="PR" Location="QueryString(PR)" DefaultValue="1"/>
          </parameterbindings>
        </WebPartPages:DataFormWebPart>

The xmlns:sharepoint="Microsoft.SharePoint.WebControls" declaration is there, so I really don't know why I get that error...

UPDATE #1 :

If I try to use this code (from the suggested method) :

I get another error :

Type 'Microsoft.SharePoint.WebControls.AttachmentsField' does not have a public property named 'xmlns:sharepoint'.

Update #2 : By the way, the dataview is in a page layout. Maybe that's the problem?

share|improve this question

3 Answers 3

I am surprised to hear that the method described by Anderson's blog didn't work. Anyhow, I was approached with the same problem, but I took a different approach for the fun of it. I used JavaScript + jQuery to modify the list.

  1. Navigate to your SharePoint site using your web browser.

  2. Select the list. (Usually on the left hand side depending on your theme and permissions).

  3. Make sure the “Attachments” columns is part of the view. If it is, skip the next step.

  4. Modify the current view by clicking on “All Items” then “Modify this View”. Then be sure the “Attachments” column is selected. Then click OK. Also, make it the first column if it is not.

  5. Now click on “Site Actions” , “Edit Page”, then “Add a Web Part”

  6. Add a “Content Editor Web Part” Paste the JavaScript described in this blog post.

Mind you this approach has its disadvantages as described in the blog.

share|improve this answer
    
Well, I ended up adding a "hyperlink" field in the content type then I just display it. Less of a good solution for the client but the JAvaScript has it's problems too (it's an Internet WebSite, not an Intranet so...) –  Anonymous Sep 7 '10 at 13:19

Take a look at this post my Marc Anderson and see if it helps: http://sympmarc.com/2010/05/26/using-sharepointattachmentsfield-in-a-dvwps-xsl/

share|improve this answer
    
That's the method I tried. I updated it with another way of displaying it. still not working :( –  Anonymous Jul 6 '10 at 17:19

I'm a bit late to this answer, stumbled across it from google. But the problem you are having is because the xmlns declaration in your stylesheet has a lowercase S. it should be xmlns:SharePoint

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.