[Original] display the list attachment as an image in dataformwebpart (2) [How to display list item attachments as image in dfwp Part 2]

Source: Internet
Author: User

In the first part, attachments are displayed as images. They can only be displayed on the site where the list is located. after a long time of experimentation, I found that when attachmentfield is cross-transferred, its internal itemcontext can only be the context of the currently accessed site, therefore, the corresponding list and field will be searched down on the current site, which leads to the inability to be found at all, so nothing will be displayed.

After confirming that it is impossible to use attachmentfield for Cross-Site display of attachments, I re-wrote a control to generate the same output as attachmentfield.

 Using System; Using System. Collections. Generic; Using System. LINQ; Using System. text; Using System. Web. UI; Using System. Web. UI. webcontrols; Using Microsoft. SharePoint; Using System. Web. UI. htmlcontrols;Using Microsoft. Sharepoint. Security; Using System. Web; Using System. Security. permissions; Namespace Only. splibraryextend. webcontrols { /// <Summary>      /// Used to display the Attachment List. The output of the attachmentfield of Sharepoint is fully simulated.      /// </Summary> [Export pointpermission (securityaction. inheritancedemand, objectmodel = True ), Aspnethostingpermission (securityaction. inheritancedemand, level = aspnethostingpermissionlevel. Minimal), using pointpermission (securityaction. linkdemand, objectmodel = True ), Aspnethostingpermission (securityaction. linkdemand, level = aspnethostingpermissionlevel. Minimal)] Public   Class Attachmentsfield: Control { Public   Int Itemid {Get; set ;} Public   String Listname {Get; set ;} Public   String Weburl {Get; set ;} Protected   Override   Void Createchildcontrols (){Base . Createchildcontrols (); spsite site = spcontext. Current. Web. Site; Using (Spweb web = site. openweb (weburl) {splist list = web. Lists [listname]; splistitem item = List. getitembyid (Itemid); htmltable table = New Htmltable (); table. attributes [ "ID" ] = "Idattachmentstable" ; Table. Border = 0; table. cellspacing = 0; table. cellpadding = 0; Foreach (String attachmentname In Item. attachments) {string attachmentabsoluteurl = item. attachments. urlprefix + attachmentname; htmltablerow TR = New Htmltablerow (); tr. attributes [ "ID" ] = Guid. newguid (). tostring (); htmltablecell cell = New Htmltablecell (); cell. attributes [ "Class" ] = "Ms-VB" ; Htmlgenericcontrol span = New Htmlgenericcontrol ( "Span" ); Span. attributes [ "Dir" ] ="LTR" ; Htmlgenericcontrol A = New Htmlgenericcontrol ( "" ); A. attributes [ "Tabindex" ] = "1" ; A. attributes [ "Onmousedown" ] = @ "Return verifyhref (this, event, '0', 'sharepoint. opendocuments.3 ',''); Return false ;" ; A. attributes [ "Onclick" ] = @ "Dispdocitemexwithserverredirect (this, event, 'false', 'sharepoint. opendocuments.3', '0',''); Return false ;" ; A. attributes ["Href" ] = Attachmentabsoluteurl; A. innertext = attachmentname; span. Controls. Add (a); cell. Controls. Add (SPAN); literalcontrol nbsp = New Literalcontrol ( "& Nbsp ;" ); Cell. Controls. Add (nbsp); tr. cells. Add (cell); table. Rows. Add (TR );} This . Controls. Add (table );}}}}

The Itemid, weburl, and listname must be configured for this control to locate the corresponding item. these three attributes are the same When configuring dataformwebpart for cross-to-Cross-display data. Of course, these three attributes are configured on the parameters of the spdatasource object when dataformwebpart is cross-site. to embed this control into dataformwebpart, you must

[Original] how to embed custom controls in dataformwebpart [How to embeded custom control in dfwp]ArticleSo add the following content to dataformwebpart:

<  XSL: Element   Name  = "Only: attachmentsfield"  >      <  XSL: attribute   Name  = "Runat"  > Server </  XSL: attribute  >      <  XSL: attribute   Name  = "Listname"  > Campus Enterprises </ XSL: attribute  >      <  XSL: attribute   Name  = "Weburl"  > /Admin </  XSL: attribute  >      <  XSL: attribute   Name  = "Itemid"  > <  XSL: value-   Select  = "@ ID"   /> </  XSL: attribute >  </  XSL: Element  > 

The final display effect of the corresponding CSS is:

Technorati tags: Sharepoint, dfwp, dataformwebpart

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.