24 August 2008

Why isn´t there a NotesDatabase.WebFilePath property?

Maybe it exists in Domino version 8. Anyone know? If it did exist then it would sure make my life a little easier. We ran into an issue recently where NotesDatabase.FilePath returned the full filesystem path for an application we were accessing from a browser using the "Preview In Web Browser" action. If we accessed the application from a Domino server we got back the path relative to the data directory (which is what we want). However, if we accessed the application by using the "Preview In Web Browser" action, we then got back the complete filesystem path (e.g. c:\notes\data\somepath\db.nsf). Ironically, Tommy Valand blogged on this same issue just last week. Unfortunately, we can't use his solution since we aren't processing any documents at the time we need to get the web file path of a database. Luckily for us in our need for accessing the FilePath method is that we already know the relative path and dbname since it's passed on the query string on our call to an agent. So, for now, we'll just not use the FilePath property and hope to one day see a WebFilePath property.
1. 8/25/2008 1:43:31 AM, Tommy Valand wrote:

There is a solution when not using documents as well. Thanks to all design elements being documents themselves.

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( |@ReplaceSubstring( @DbName[2] ; "\\" ; "/" )|, viewDoc ) )

End Function

I'll update my post with this code, if the above code is killed by the blog parser..

2. 8/25/2008 3:27:27 AM, Per Gref wrote:

Can't you use @WebDbName?

Function webFilePath() As String

webFilePath = Join(Evaluate(|@WebDbName|))

End Function

3. 8/25/2008 4:22:42 AM, Tommy Valand wrote:

@Per: That only returns the path to the current database, the database that runs the agent.

If Jack's problem was the same as mine, the agent he has needs to get the (web)filepath from another database than the one running the agent.

4. 8/25/2008 5:43:46 AM, Jack Ratcliff wrote:

@Tommy: That's fantastic! I'll try that out.

@Per: Like Tommy said, I can't use that since @WebDbName only returns the path of the current database and I need the path of another db.

5. 8/25/2008 9:08:08 AM, Tim Tripcony wrote:

Jack,

Here's what I use:

Function webFilePath (Source As NotesDatabase)

Dim dbPath As String

Dim dataDirectory As String

Let dbPath = Replace("/" & Source.FilePath, "\", "/")

Let dataDirectory = Replace(Source.Parent.GetEnvironmentString("Directory", True), "\", "/")

Let webFilePath = Replace(Replace(dbPath, dataDirectory, ""), "//","/")

End Function

If the database is considered local, then the filepath starts with the directory variable from the INI, which the above function replaces with "". Otherwise that replacement does nothing. One pet peeve, though: sometimes the INI variable ends in a slash, sometimes it doesn't... hence the forced double-slash replacement.

6. 8/25/2008 9:46:23 AM, Jack Ratcliff wrote:

@Tim: very cool. Is there any overhead to calling the GetEnvironmentString method? If so, then the Source.Server property could be checked first and only if it is blank (which would mean the db is local) call the GetEnvironmentString property.

7. 8/25/2008 11:29:57 PM, Tim Tripcony wrote:

I haven't seen noticeable overhead. INI queries are fairly quick... but you're right, checking Source.Server would let you know in advance whether the Data path replacement is even necessary.

8. 8/26/2008 12:23:45 AM, Per Gref wrote:

OK then... Tims version has extremely good performance but requires "Unrestricted Access" as it reads environmentals. May or may not be an issue.

For my own future use I'll file a @WebDbName version of Tommys view-doc trick, it has the same performance:

Function webFilePath(db As notesdatabase) As String

webFilePath = Join(Evaluate(|@WebDbName|, db.GetDocumentByUNID(db.Views(0).Universalid)))

End Function

100 Iteration Performance Test

------------------------------

09:07:27

100: @WebDbName

09:07:34

09:07:34

100: Tim Tripcony Environment Dir

09:07:34

09:07:34

100: Tommy Valand @ReplaceSubstring

09:07:41

Add a new comment

(not displayed)
Remember Me?