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

Can SharePoint 2010 BCS return multiple attachments? I have a database which stores multiple attachments per entity. Would like to have all of them accessible, but I've insufficient experience with BCS/BDC to say whether or not this is possible.

share|improve this question
    
Did you ever got this figured out? I have the exact same issue and trying to gather ideas on how to solve it.. –  JohnnyT Feb 8 '13 at 15:37
add comment

2 Answers

up vote 2 down vote accepted

Yes you can have n number of attachments by using streamaccessor method. See the code below that has two methods. One for picking up the main document and other for picking up the additional document. In the code behind you can use the same function to return the stream object. Let me know if you need any further assistance as I have already implemented this many times.

        <!-- start document StreamAccessor method -->
        <Method Name="ReadDocumentLink" IsStatic="false" LobName="ReadDocumentLink" IsCached="true">
          <Parameters>
            <Parameter Direction="In" Name="@Id">
              <TypeDescriptor TypeName="System.Int32" IdentifierName="ID" Name="ID" />
            </Parameter>
            <Parameter Name="StreamData" Direction="Return">
              <TypeDescriptor Name="StreamData" TypeName="System.IO.Stream" />
            </Parameter>
          </Parameters>
          <MethodInstances>
            <MethodInstance Type="StreamAccessor" ReturnParameterName="StreamData" ReturnTypeDescriptorPath="StreamData" Default="true" Name="MainDataStream" DefaultDisplayName="Document">
              <Properties>
                <Property Name="MimeTypeField" Type="System.String">DocumentMimeType</Property>
                <Property Name="FileNameField" Type="System.String">DocumentFileName</Property>
                <Property Name="Extension" Type="System.String">DocumentExtension</Property>
              </Properties>
            </MethodInstance>
          </MethodInstances>
        </Method>
        <!-- end document StreamAccessor method -->


        <!-- start document StreamAccessor method -->
        <Method Name="ReadAdditionalDocumentLink" IsStatic="false" LobName="ReadAdditionalDocumentLink" IsCached="true">
          <Parameters>
            <Parameter Direction="In" Name="@Id">
              <TypeDescriptor TypeName="System.Int32" IdentifierName="ID" Name="ID" />
            </Parameter>
            <Parameter Name="StreamData" Direction="Return">
              <TypeDescriptor Name="StreamData" TypeName="System.IO.Stream" />
            </Parameter>
          </Parameters>
          <MethodInstances>
            <MethodInstance Type="StreamAccessor" ReturnParameterName="StreamData" ReturnTypeDescriptorPath="StreamData" Name="AdditionalDataStream" DefaultDisplayName="Additional Document">
              <Properties>
                <Property Name="MimeTypeField" Type="System.String">AdditionalDocumentMimeType</Property>
                <Property Name="FileNameField" Type="System.String">AdditionalDocumentFileName</Property>
                <Property Name="Extension" Type="System.String">AdditionalDocumentExtension</Property>
              </Properties>
            </MethodInstance>
          </MethodInstances>
        </Method>
        <!-- end document StreamAccessor method -->
share|improve this answer
add comment

If by "multiple attachments per entity" you mean that you have multiple binary columns in SQL table then I suggest you try to create StreamAccessor methods in your BCS Model for each column, see details here:

XML Snippet: Modeling a StreamAccessor Method

You can display links to the binary content in Business Data Web Part with custom XSLT like this:

<a>
  <xsl:variable name="downloadUrl" select="concat($DownloadExternalDataUrl, ddwrt:UrlEncode('BCSStreamAccessorMethodInstanceName'), '&amp;IsXmlEncodedStreamName=true&amp;ItemId=', @*[name()=$ColumnKey])" />
  <xsl:attribute name="href">
    <xsl:value-of select="$downloadUrl" />
  </xsl:attribute>
  <xsl:attribute name="onclick">javascript:DownloadExternalData('BCSStreamAccessorMethodInstanceName', '<xsl:value-of select="@*[name()=$ColumnKey]" />', '<xsl:value-of select="concat($downloadUrl, '&amp;InvisibleFrame=true')" />'); return false;</xsl:attribute>
  <xsl:value-of select="@tpar_binary_fname" />
</a>
<span style="display:none">
  <iframe>
    <xsl:attribute name="name">
      <xsl:value-of select="concat('BCSStreamAccessorMethodInstanceName', @*[name()=$ColumnKey], 'DownloadFrame')" />
    </xsl:attribute>
  </iframe>
</span>
share|improve this answer
add comment

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.