现在的位置: 首页 > 综合 > 正文

XPages and 8.5 Discussion Template – a Fix for the File Download Control2009-04-28 07:49

2012年08月01日 ⁄ 综合 ⁄ 共 2022字 ⁄ 字号 评论关闭
Many people have been asking for my help with a problem with the 8.5 Discussion template's File Download control.  The reason is that I have an example of a Custom Control for storing file attachments in a central database which uses the File Download control and has the same issue.

The issue with the File Download control in XPages is that it does not launch Microsoft attachments properly when using Internet Explorer.  The secondary issue is that it throws an exception if your database is in a subdirectory.  You can read the details here in the 8.5 Discussion forum.  

Last week Irina Kojevnikova posted a solution to the problem.  Her solution overrides the File Download control's HREF for each attachment.  

Here is a description of the solution:

On the All Properties tab for the File Download control, there is a property fileNameHrefValue which is computable.

Image:John's Blog - XPages and 8.5 Discussion Template - a Fix for the File Download Control

The JavaScript for the value computes the url for each attachment by referencing the current row using the data->var property value rowData.  As the control loops through the attachments, we can get the name of each attachment by using rowData.getName(). Now we can use the filename to build a new url for each attachment.

Image:John's Blog - XPages and 8.5 Discussion Template - a Fix for the File Download Control

The data var property is set on the All properties tab under the data section.
Image:John's Blog - XPages and 8.5 Discussion Template - a Fix for the File Download Control

The end result is a url similar to: http://localhost/TestDiscussion.nsf/0/A8364817576EF43F852575A30043E76D/%24FILE/JohnExcel.xls

One issue I could not completely resolve was that if the user attaches files and the document has not been saved yet, the new url will not work since it is using the universalID.  Most likely the person that uploads a file will not try and launch it immediately, though they might want to delete it.  So I replaced the href with "#" if it is a new document so there will not be an error message if the user clicks on the file...it will do nothing.  If anyone has a suggestion on a different approach, please let me know.

I updated the discussion8.ntf template with the fix and you can download that here: discussion8.ntf.  You will need to sign the database with a production id for use on your server, or sign the 3 custom controls I updated: mainTopic, response, and viewTopic.  I also updated my Custom Control for storing file attachments in a central database with the fix.

Thank you to Irina for putting together a solution!  Also, a special thanks to Richard Cotrim who spent some time this weekend testing the solution.

抱歉!评论已关闭.