Marc's profileMarc DavisBlogListsNetwork Tools Help

Blog


    April 28

    Retaining Attachment functionality when using the Custom List Form control in SharePoint 2007 or WSS 3.0

     

    Retaining attachment functionality when using the Custom List Form Control in SharePoint 2007 / WSS 3.0

    If you have found this post then you are just one of many people who have been frustrated by a ‘feature’ in SharePoint 2007 (or WSS 3.0) whereby you lose the Attachment functionality if you replace the standard list form control with the Custom list form control within SharePoint Designer. I recently ran into this problem while trying to dress-up some standard forms in my SharePoint deployment.

    Like many of you I searched the Internet & tried many of the user-inspired workarounds. But I could not find any usable solution. So I spent a week working with Microsoft – who acknowledged the problem exists – but no solution was forthcoming. Finally I got a hold of our account representative and laid into him about this issue and the lack of a workaround. Well, 3 phone calls later followed by an Impact Analysis (and a bit of groveling) I managed to get an unsupported workaround out of Redmond.

    I’ve managed to clean the process up a bit – hopefully it will go smoothly for you. That being said – here is the usual disclaimer: This is an unsupported workaround – no warranties or guarantees. Always backup your system before making a change of this nature.

    And to be safe – here is the official disclaimer from Microsoft. Just so we are clear:

     Important Disclaimer: The information contained in this document is not supported under any Microsoft™ standard support program or service, and is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the information contained in this document remains with you. In no event shall Microsoft, its authors, or anyone else involved in the implementation or configuration of the information contained in this document be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the information contained in this document, even if Microsoft has been advised of the possibility of such damages.

    OK – Let’s get started.

    First – a very brief understanding of the problem. WSS 3.0 does not implement the SharePoint custom list form control properly. The code blocks for the Attach File functionality are missing when the page is rendered in SharePoint. Many users have tried to reverse engineer the missing pieces with limited success. This workaround implements a new DLL which takes the place of the missing functionality.

    Prerequisites

    1.       You will need the following files from my SkyDrive Public folder:

    a.       http://cid-6d5649bcab6a7f93.skydrive.live.com/self.aspx/Public/SPDataSourceEx.zip

    b.      http://cid-6d5649bcab6a7f93.skydrive.live.com/self.aspx/Public/SPXSLT_BLOCK1.txt

    c.       http://cid-6d5649bcab6a7f93.skydrive.live.com/self.aspx/Public/SPXSLT_BLOCK2.txt

    2.       You will need Visual Studio 2005 or Visual Studio 2005 Express Edition to rebuild the solution provided in the ZIP file above. A precompiled DLL is included in the ZIP file if you experience problems building it.

    3.       You will need access to the SharePoint Server(s) to install a DLL into the Global Assembly Cache.

    4.       You will need the .NET Framework 2.0 SDK installed or the ability to drop the DLL into the Windows\Assembly folder.

    Actions to be performed on the Server(s)

    1.       Download the ZIP file to a computer that has Visual Studio 2005 installed and rebuild the Solution using the ‘Release Configuration’. The resulting DLL will be in the ‘\SPDataSourceEx\bin\Release’ folder: SPDataSourceEx.DLL

    2.       Install the SPDataSourceEx.DLL into the Global Assembly Cache of the SharePoint Servers. You can use GACUTIL.EXE or you can copy the file directly into the \Windows\Assembly folder from the server console. Be sure to install the DLL on all of the SharePoint servers in the farm.

    3.       Once the DLL is installed in the GAC you will need to register it as a Safe Control for the SharePoint web application. Add the following line to the web.config file:

    <SafeControl Assembly="SPDataSourceEx, Version=1.0.0.0, Culture=neutral, PublicKeyToken=78678792a547c409" Namespace="SharePoint" TypeName="*" Safe="True" AllowRemoteDesigner="True"/>

    Note: Be sure you modify the correct web.config file. SharePoint servers have a number of web.config files depending on the number of sites and SSPs. Also – make sure each server’s web.config file is the same (if you have more than one SharePoint server).

    4.       Perform an IISRESET on all servers in the farm.

    Actions to be performed within SharePoint Designer 2007

    1.       Open a list within SharePoint Designer that you want to modify. These steps will need to be performed on any page that you use the Custom List Form Control and desire the Attachment functionality to work as advertised. For this example we’ll be working with the NewForm.aspx file. Only minor differences from these instructions are needed for the EditForm.aspx file and they are noted inline. The DispForm.aspx edits are easier and will be described at the end of this document.

    2.       Open the NewForm.aspx file for the list you want to customize.

    3.       Right-click on the ListFormWebPart and click ‘Web Part Properties’. Expand ‘Layouts’ and select ‘Close the Web Part’ and ‘Hidden’. Click OK to close. This step is VERY IMPORTANT. You DO NOT want to delete the existing ListFormWebPart from the page. Doing so will cause SharePoint to detach the page from the navigation system and you will not be able to fix it short of deleting the list, restoring the content database, or restoring the list if you happen to have a recovery tool that can recover individual lists.

    4.       Add the following directive to the top of the page under the existing directives:

    <%@ Register tagPrefix="BoADataSource" Namespace="SharePoint" Assembly="SPDataSourceEx, Version=1.0.0.0, Culture=neutral, PublicKeyToken=78678792a547c409" %>

    5.       Now we are ready to insert the Custom List Form. Position the cursor immediately below the now disabled ListFormWebPart and click on Insert, SharePoint Controls, Custom List Form. Select the correct List, and choose New Item Form (or Edit Item Form if modifying the EditForm.aspx file)

    6.       Switch to Code View. Use Find/Replace to change ‘SharePoint:SPDataSource’ to ‘BoADataSource:SPDataSourceEx’.

    Note: If after replacing this string the Custom Form control fails to render when switching back to Design View, save the file and close SharePoint Designer. Then reopen the file. If the control continues to generate a rendering error you can switch the string back to its original value for the remainder of the steps and change it at the end before testing. This may also indicate that the DLL is not registered properly on the server(s) – verify the web.config file and be sure to do an IISRESET. Then restart SharePoint Designer.

    7.       The next several steps involve modifying several XSL code blocks within the Custom List Form control. This is best done in Code View. Rather than clutter this document with XSL that won’t cut & paste cleanly I have put the changed code in SPXSLT_BLOCK1.TXT. Find the indicated block and replace it with the modified code.

    Note: The XSLT code needs to have the ControlMode set to “New” for the custom New Item form and “Edit” for the custom Edit Item form. It is currently set to “New”.

    8.       Now we are going to add an extra table row to display the attachments dynamically after they’ve been added. This section will not be visible on the published form until a file has been attached. Use ‘Find’ to locate the following line of code:

    <xsl:if test="$dvt_1_automode = '1'" ddwrt:cf_ignore="1">

    Paste the code block in SPXSLT_BLOCK2.TXT directly above this line.


    Note 1: The XSLT code needs to have the ControlMode set to “New” for the custom New Item form and “Edit” for the custom Edit Item form. It is currently set to “New”. Additionally, in the __designer.bind attribute, the first parameter for the ddwrtDataBind Function should be set to ‘i’ for the custom New Item form and ‘u’ for the custom Edit Item form.


    Note 2: After saving the file with the modified code, you may notice the Script section changes slightly. This is normal.

    9.       If you ran into the rendering problem from Step 6, replace that string now and save the file. If all went well, you can create a new item in your list and attach a file just as you normally would if the page was still using the standard list form control.

    10.   Now you can go back to your modified page and customize the control as you see fit – i.e. moving items around, hide unwanted fields, etc.

    Custom List Form for DispForm.aspx

    To add attachment functionality to the DispForm.aspx (or any other Display form) do the following:

    1.       Open SharePoint Designer 2007; Click on File, Open Site and connect to your SharePoint Site.

    2.       Browse to the desired list, expand out ‘Lists’, and open DispForm.aspx (or another Display Form)

    3.       Right-click on the ListFormWebPart and click ‘Web Part Properties’. Expand ‘Layouts’ and select ‘Hidden’. Click OK to close. This step is VERY IMPORTANT. You DO NOT want to delete the existing ListFormWebPart from the page. Doing so will cause SharePoint to detach the page from the navigation system and you will not be able to fix it short of deleting the list, restoring the content database, or restoring the list if you happen to have a recovery tool that can recover individual lists.

    4.       Now we are ready to insert the Custom List Form. Position the cursor immediately below the now hidden ListFormWebPart and click on Insert, SharePoint Controls, Custom List Form. Select the correct List, and choose Display Item Form.

    5.       Depending on where you want the Attachments to display – put your cursor in a table cell within the custom form control and right-click, Insert, Row Below. There should now be a new table row with two columns.

    6.       Put the cursor in the left table cell of the new row and type ‘Attachments’.

    7.       Now put the cursor in the right table cell of the new row; goto Code View, and paste the following line:

    <SharePoint:AttachmentsField ControlMode="Display" FieldName="Attachments" runat="server" Visible="true"/>

    8.       Save the file and test.

    Some Known Issues and Workarounds

    1.       You might see an error in rendering the SharePoint:AttachmentUpload control (usually appears below the custom form). This is a benign rendering issue and should not affect the functioning of the page outside of SharePoint Designer.

    2.       When you close and open the site – the first time you open the custom list form control – you might see that the controls do not render. If you close and reopen the page again the control should start rendering properly.

    3.       If you make more changes to the page you might see that SharePoint Designer automatically tries to add a unique ID to the attachment code that was added. This may cause some JavaScript errors in the page when browsing. If this happens, you will find the ‘<tr id=”idAttachmentsRow”>’ line being changed to ‘<tr id=”idAttachmentsRow{generate-id}”>’. You can safely delete the {generate-id} tag that gets added. This should resolve the JavaScript error.

    4.       You may (i.e. probably will) see this error message: “The data source control failed to execute the insert command” when trying to submit the form in the browser. To resolve it, do one or both of the following:

    a.       Check Step 6 above. This error can be caused by the DLL not being registered properly. If you had to skip Step 6 earlier – you may still have this problem.

    b.      Try moving the Custom List Form control outside of the web part zone. Place it directly after the </WebPartPages:WebPartZone> tag.

    5.       Remember – you do not want to delete the existing ListFormWebPart control. Doing so will cause all kinds of problems that will result in you deleting the entire list. Please, backup your content database. You will thank me later.

    Well that is it. I’m glad to say that the above solution resolved my Attachment issue with the Custom List Form control. I hope it can help you. Oh – and the official word from Redmond is that this ‘behavior’ will not be fixed in the current version of SharePoint. Now I truly appreciate Microsoft releasing this workaround to me. But there are so many other people having this problem that to not publish a workaround (even an unsupported one like many fixes are) is a disservice – especially since they’ve had this workaround since December 2007. Ok, rant over. Peace.

    UPDATE: I'd like to thank Mike Mongeau for posting about this issue (and this workaround) on the SharePoint Designer Support Team Blog (http://blogs.msdn.com/spdsupport/archive/2008/04/29/cat-s-out-of-the-bag-how-to-get-back-attachment-functionality-with-custom-list-forms.aspx). It is definately good to hear that a real fix may be in the works. I fully agree with Mike that a supported fix is the best solution, and while this workaround is not very elegant, it does seem to work. So again, thanks to whoever (presumably Mike's team) developed the workaround and I look forward to seeing the official fix in the future.

     

    Microsoft, SharePoint, WSS, and SharePoint Designer are trademarks of Microsoft Corporation. All other trademarks are the property of their respective companies.

    Comments (84)

    Please wait...
    Sorry, the comment you entered is too long. Please shorten it.
    You didn't enter anything. Please try again.
    Sorry, we can't add your comment right now. Please try again later.
    To add a comment, you need permission from your parent. Ask for permission
    Your parent has turned off comments.
    Sorry, we can't delete your comment right now. Please try again later.
    You've exceeded the maximum number of comments that can be left in one day. Please try again in 24 hours.
    Your account has had the ability to leave comments disabled because our systems indicate that you may be spamming other users. If you believe that your account has been disabled in error please contact Windows Live support.
    Complete the security check below to finish leaving your comment.
    The characters you type in the security check must match the characters in the picture or audio.
    Marc Davis has turned off comments on this page.
    Oct. 13
    Oct. 13
    Oct. 13
    Oct. 13
    Picture of Anonymous
    Oct. 12
    Oct. 10
    Oct. 10
    No namewrote:
    Want to go to tibet tour? You can rely on us! We are expert in tour in tibet. based in Tibet 15 years experience, 600 private groups operated! So join us for your wondrous tibet travel! Are you interested in mysterious Lhasa travel to tibet? Why not take our Lhasa tibet trekking? You can appreciate the holiness of Lhasa tibet tour guide with our well-connected itinerary and leave a memorable recollection over life. These are China Lhasa tibet tangka packages with personal local tibet map, and private vehicle with driver + hotels + entrance fees and meals as listed for your party based on minimum 2 travelers. Tibet Buddhist Sects and Characteristics, For single person, please email us for new quotations. For any questions, please feel free to contact our customer team with our prompt and personalized travel services.
    Oct. 8
    No namewrote:
    wow goldWorld of Warcraft would like to create a myth of immortality? mmoinn.com desire to help you achieve, <a href="http://www.mmoinn.com"> buy wow gold </a> from mmoinn.com, you will get an unexpected price, there is cheapest wow gold and <a href="http://www.gold-warhammer.com"> warhammer gold </a>, also world of warcraft sale in the
    <a href="http://www.mmoinn.com/mmoinn_pl/"> wow power leveling </a>, Heart of it! As soon as possible to mmoinn.com <a href="http://www.mmoinn.com"> buy wow gold </a> it! Let your role with mighty.
    Oct. 8
    Picture of Anonymous
    Oct. 7
    Picture of Anonymous
    升降机 wrote:

    外媒称神七伴飞小卫星具攻击性发射中心否认无缝管 升降平台谷歌手机GPhone今日将亮相据称上网速度最快弹簧升降机数据恢复 升降机 RAID数据恢复 北京心理咨询服务器数据恢复 液压升降机 无缝钢管 升降平台 博客 升降机 Google排名微软199元Office 2007只能安装1台电脑网站优化 心理咨询 升降机 升降机 升降平台 登车桥 升降机 铝合金升降机 液压机械 升降台 高空作业平台 升降机合并前夕总经理泪洒庆功会

    联通重启终端公司注资5亿元组建联通华凯同声传译 会议设备租赁 同声翻译设备 文件柜 论文发表 同声传译设备租 赁 同声传译 表决器租赁 更衣柜 论文发表 会议设备租赁网络公关已成摆布舆论工具

    联想欲接手富士通西门子PC业务Prefessional wow gold Site supply Cheap WoW Gold and World Of Warcraft Gold service.Tips to Buy wow gold482名硕士博士告万方侵权案22日在北京开庭making guide WoW Gold,Buy wow gold,Cheap WoW Gold,World Of Warcraft Gold被刺伤的辉煌:IE 8平台化迎接浏览器核战

    上海高校教授发出呼吁警惕文学史写作"垃圾化"Our company's products are Gas Alarm,Gas Detector,Breathalyser,Breathalyzer,Alcohol Tester,Co Alarm.Breathalyzer谷歌是非美式文化的侵略者还是鲶鱼Gas Alarm Breathalyser Co Alarm Co Detector Alcohol Tester Alcohol Tester Gas Detector Please select one of our product categories to find out more毛瑞斯莫爆冷负于东欧新秀中网首轮惨遭淘汰

    Oct. 7
    No namewrote:
    東京/大阪のクリエイター育成専門の学校 バンタンデザイン研究所。大阪 専門学校ファッションや美容の専門の学校です. 大阪 専門学校デザインスクール最大級の超複合型イベント
    Oct. 6
    Oct. 6
    Oct. 6
    Sept. 29
    No namewrote:
    tangjewelry professionally engaged with wholesale jewelry,jewelry store,fashion jewelry,crystal jewelry,jewelry wholesale,pearl jewelry,beaded jewelry,swarovski crystal jewelry,wholesale pearl,wholeslae turquoise,semi-precious jewelry,coral jewelry,shell jewelry,wholesale crystal
    Sept. 29
    Sept. 28
    No namewrote:

    One of the most wow gold the best wow gold systems in buy wow gold World of Warcraft's buy wow gold design is it cheap wow gold player-based cheap wow gold auction system. Much like an internal world of warcraft gold eBay, the auction houses fast wow gold of the world link sell wow gold all the major cities age of conan gold together in an aoc gold open trade ffxi gil environment. Characters residing warhammer gold in the ruins known as runescape gold Undercity tibia gold can trade their goods with the orcs swg credits and trolls lotro gold of Orgrimmar. 2moons dil Meanwhile, dwarves maple story mesos of Ironforge eve isk can sell ore and lineage 2 adena goods eq2 plat to their elven wow power leveling friends on wow power leveling the far off city of Darnassus power leveling. Alliance and world of warcraft power leveling Horde characters wow power level can even trade amongst wow leveling themselves, wow leveling in the power leveling goblin run wow gold free cities of buy wow gold Gadgetzan, Everlook cheap wow gold and Booty world of warcraft gold Bay. The economy wow power leveling of World of power leveling is a robust, living entity, controlled world of warcraft power leveling entirely by the players of the world.

    Sept. 27
    Sept. 18
    Sept. 18

    Trackbacks

    The trackback URL for this entry is:
    http://cid-6d5649bcab6a7f93.spaces.live.com/blog/cns!6D5649BCAB6A7F93!130.trak
    Weblogs that reference this entry
    • None