This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal



Aug 26, 2013, 7:56 PM
18 Posts

Launch an Attachment

  • Category: Extension Library
  • Platform: All
  • Release: 9.0
  • Role: Developer
  • Tags: file download
  • Replies: 5

I have a very simple requirement that seems like it is far harder than it has to be. 

I need to display an Xpage that has a file attachment, and if a user clicks the link, the attachment (a PDF) opens. This is really really easy in Notes. Searched for an hour now and cannot find a simple solution to this.....

Aug 26, 2013, 9:36 PM
366 Posts
That's a browser / client behavior

If you see the rendered attachment, then a user would have to double click to "launch" it.

 

Depending upon what browser is being used and if they have a pdf reader installed on their client, they will either be prompted to download or view it.

Aug 26, 2013, 9:56 PM
18 Posts
How to attach it

Paul,

How can I attach an attachment to an Xpage so the user can view it, click it, and the view it or download it?

Bryan

Aug 27, 2013, 12:47 PM
366 Posts
Are you talking about an upload control?

The XPage simply exposes the underlying document data source.  So you don't attach anything to the XPage, but the underlying document.

 

You do that the way you have always done it if you are doing it programatically.  If needing to add an attachment via XPages then bind a file upload/download control to a Rich Text Field on the document data source.

 

 

Aug 27, 2013, 5:16 PM
18 Posts
Clarification

 

Paul,

You are correct. I have done more research to understand this correctly. Thanks for reminding me about the data source.

1. I have created a form and view in which I can add an attachment. 

2. In a test Xpage I have a link with this code behind the link:

docID  = "C8B2303F9D74E0E786257BD3006E2D03";

attNme  = "Scoular Corporate Aircraft Use Policy (11-18-11).pdf";

var imgURL = facesContext.getExternalContext().getRequest().getContextPath() + "/0/" + docID + "/$File/"+ attNme;

 

imgURL

 

This works in the web GREAT - the attachment opens.

In the client (9.0.0.0) I get the following error.

Error 500: Unexpected Error Condition.

 

I also have found a separate article that suggests doing this:

 

docID = "C8B2303F9D74E0E786257BD3006E2D03";

attachmentName = "Scoular Corporate Aircraft Use Policy (11-18-11).pdf";

 

function getAttachmentURL(docID, attachmentName) {

var base = getBaseURL();

var middle = "/xsp/.ibmmodres/domino/OpenAttachment";

if (base.substr(0,4) == "/xsp") {

 middle += base.substr(4);

} else {

 middle += base;

}

var result = base + middle + "/" + docID + "/Body/" + attachmentName + "?Open";

return result;

}

 

function getBaseURL() { 

var curURL = context.getUrl();

var curAdr = curURL.getAddress();

 var rel = curURL.getSiteRelativeAddress(context);

 var step1 = curAdr.substr(0,curAdr.indexOf(rel));

 

 // Now cut off the http

var step2 = step1.substr(step1.indexOf("//")+2);

var result = step2.substr(step2.indexOf("/"));

return result;

}

 

//getAttachmentURL(docID, attachmentName);

 

 


This doesn't seem to work. 

 

Would love to know how to get the first example to work in the client.

 

 

Aug 29, 2013, 7:26 PM
586 Posts
Client

I forget the details...  but I think the issue is the client (XPiNC) has a slightly different naming structure regarding URL's.  Suggest you search on that maybe.  It's a pain - a real turn off to client dev I think that you have to be aware of some differences like that.


This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal