0
votes

I have a strange issue occurring with generating URLs to attachments stored on a notes document.

The Xpage that displays the notes document has a repeat that retrieves the embedded objects from the body field with this code:

var doc:NotesDocument = docEmail.getDocument();
if (doc.hasEmbedded()){
    var rtItem:NotesRichTextItem = doc.getFirstItem("Body");
    return rtItem.getEmbeddedObjects()
}

I then have a hidden input field that stores the URL generated by this code (colBodyAttachments is the repeat collection name):

var doc:NotesDocument = docEmail.getDocument();
var dbComms = doc.getParentDatabase();

var dbServer = ReturnSvrHostName(dbComms.getServer())
var dbPath = @ReplaceSubstring(dbComms.getFilePath(), '\\', '/');
var attachmentName = colBodyAttachments.getName()

return "http://" + dbServer + "/" + dbPath + "/0/" + doc.getUniversalID() + "/$FILE/" + attachmentName

That works fine on 99.9% of the docs however it doesn't seem to generate the URL correctly when I have attachments with a name like this: "120531.Whytes Invoice # 701537.pdf"

The URL that is produced looks like this:

http://website.com/database.nsf/0/ABA667304AB04454CC257A4F0015D321/$FILE/120531.Whytes%20Invoice%20# 701537.pdf

It doesn't encode the %20 after the # and even if I try to do that I still get an 'Item Not Found Exception'. Is there issues encoding a url when a hash is present? Or with domino finding the attachment when a hash is present?

1
Did you try to use XSPUrl.encodeParameter to get an encoded string?Torsten Link
This saw me right, thank youAndrew Norrie

1 Answers

6
votes

The # sign breaks the URL. It is the separator between a location and a place inside that location. You need to encode it. Also xpages attachments follow a slightly different format. See: http://www.wissel.net/blog/d6plinks/SHWL-86QKNM