Tuesday, August 19, 2008

Getting relative dbpath on localhost

Update, 25.08.08: It appears I'm not the only one struggling with this issue. Jack Ratcliff had a similar issue. The difference being that he didn't have a document to process.

Since all databases are required to have one view, and all design-elements basically are NotesDocuments, it's easy to rewrite the code to work without needing a "real document".

Function WebFilePath( db As NotesDatabase ) As String
Dim view As NotesView
Set view = db.Views(0)

Dim viewDoc As NotesDocument
Set viewDoc = db.GetDocumentByUNID( view.UniversalID )

WebFilePath = Join( Evaluate( |@WebDbName|, viewDoc ) )
End Function



If for some reason you're not working in a HTTP-environment, use this instead of @WebDbName:
@ReplaceSubstring( @DbName[2] ; "\\" ; "/" )

--

Today, I had to make a multi-db search agent for web localhost compatible. When printing the path to the db, I had used NotesDatabase.FilePath. The problem with this is that it returns the filesystem path to the db when running locally. E.g. c:\lotus\notes\data\db.nsf

I could use NotesDatabase.ReplicaID, but I prefer somewhat readable URLs.

My solution was using evaluate @DbName[2] (the path to the database), with a document from the db I was currently processing. Without the document as second argument, evaluate would return the path to the search database.

Function printPath(resultDoc As NotesDocument) As String
Dim dbpath As String
dbpath = Join( Evaluate( |
@ReplaceSubstring(@DbName[2];"\\";"/")|,resultDoc))

printPath= "/" + dbpath + "/0/" + resultDoc .UniversalID
End Function

2 comments:

Daddy said...

What about NotesDocument.HttpUrl ?

Tommy Valand said...

Returns an empty string in my search agent.

The agent is run by ?OpenAgent.

NotesDocument.HttpURL only works with WebQueryOpen/-Save? I must admit that I've never used that property successfully.

I tried it a while back, and it returned an empty string in that case as well.