Question

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.

Was it helpful?

Solution

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 -->

OTHER TIPS

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>
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top