Welcome to the IBM Collaboration Solutions Community IQJam.
UsernamePassword
Reset Password | Register
   
Home | Leader Board | Tags | Help
XPages in Notes Client!! How to build URLs 
In the Notes Client, the URL to show an image  using the computed field (content-type html) instead of using an image control is the following.
 
/xsp/ServerName!!DbPath/imagename
 
This works fine for me. Now, I am trying to open an attachment and having difficulty in figuring out the correct URL for it. I need to open the attachment in an iframe. The html for the same is coded in a computed field (content-type html). I tried the following syntax(es).
 
/xsp/ServerName!!DbPath/ViewName/Key/$File/FileName?openelement
 
/xsp/ServerName!!DbPath/ViewName/Key/$File/FileName?SessionID=XXXXX
 
Notes://ServerName/DbReplicaID/ViewName/Key/$File/FileName
 
It gives me the error "Unknown Resource". Does anybody know how the syntax should be like? Are the standard domino URLs supposed to work the same way in XPages? (For opening view, frameset, attachment etc)
 
 
Domino Development / XPages
Tagged
Rajeev Menon - about 1 year ago |  |  | Viewed 935 times

There are 3 answers

0votes
Unfortunately in the Notes client you can't use the $FILE URL syntax. When you use this on the server you're actually using the old HTTP server to serve the attachments up to you, instead you'll need to work out which client is running and then build a different format URL for the Notes client vs the web browser.
 
Below is a set of functions which you can use (shameless plug.. as taken from my online video training site XPages101.net), it assumes that the names of the file attachments are in a field called "AttachmentNames". If they aren't then it should be an easy task to work them out.
 
/**
Builds some HTML to display the photo for a contact
*/
function getImageHTML(doc:NotesDocument){
var files = doc.getItemValue("AttachmentNames");
var out = "";
var dbPath = getDbPath();

for (var i=0; i<files.length; i++){
if (out != "")
out += "<br />";
if (files[i].toLowerCase().indexOf(".jpg") > -1 || 
files[i].toLowerCase().indexOf(".gif") > -1 || 
files[i].toLowerCase().indexOf(".png") > -1)
out += "<img class=\"viewphoto\" src=\"" + dbPath[0] + "/xsp/.ibmmodres/domino/OpenAttachment/" + dbPath[1] + "/" + 
doc.getUniversalID() + "/photo/" + escape(files[i]) + "\" />";
}
if (out != "")
out = "<div class=\"screenshotimage\">" + out + "</div>";
return out;
}

/**
Cache the dbPath variables in an applicationScope variable
*/
function getDbPath(){
if(isCacheInvalid("dbpathweb", 600)){
synchronized(applicationScope){
var dbPath = @Left(context.getUrl(), ".nsf") + ".nsf";
var pos = (context.isRunningContext("Notes")) ? 4 : 3;
var secondPathElements = dbPath.split("/");
var secondPath = "";
for (pos; pos<secondPathElements.length; pos++){
if (secondPath != "")
secondPath += "/";
secondPath += secondPathElements[pos];
}
var res:Array = new Array();
res.push(dbPath);
res.push(secondPath);
applicationScope.dbPathWeb = res;
}
}
return applicationScope.dbPathWeb;
}

/**
A generic caching mechanism for each key will check to see if it is 'n' seconds
since it was last updated. Use for things that change relatively infrequently  
*/
function isCacheInvalid(key, cacheInterval){
var currentTime = new Date().getTime();
if (!applicationScope.containsKey(key + "_time")){
applicationScope.put(key + "_time", currentTime);
return true;
}
var diffInSecs = Math.ceil((currentTime - applicationScope.get(key + "_time")) / 1000);
if (diffInSecs < cacheInterval) {
return false;
} else {
applicationScope.put(key + "_time", currentTime);
return true;
}


Matt White - about 1 year ago | 
Voting
Vote on the answer to show whether you think the answer is correct or useful to the rest of the community.

Answers with more votes are more visible to the rest of the community


0votes
Thanks Matt. It worked!!
 
But, now it asks the location to save the PDF file that I am trying to open. On the web, it opens up the PDF in the iframe which is how I want it to work on the client as well.
 
I think this particular URL syntax is derived from the "File Dowload" control and that could be the reason why it is asking to save rather than opening in the iFrame itself.
 
Do you know of any way to open the PDF inside the iFrame?
 


Rajeev Menon - about 1 year ago | 
Voting
Vote on the answer to show whether you think the answer is correct or useful to the rest of the community.

Answers with more votes are more visible to the rest of the community


0votes
I didn't think the regular web url will work just fine on the client to open the attachment. The following url worked fine, it opened the PDF in the IFrame.
 
 
So I guess, anything releated to the XPages need to have the XPages kind of Url and other classic domino URLs remain the same.


Rajeev Menon - about 1 year ago | 
Voting
Vote on the answer to show whether you think the answer is correct or useful to the rest of the community.

Answers with more votes are more visible to the rest of the community