API
@-Formulas
JavaScript
LotusScript
Reg Exp
Web Design
Notes Client
XPages
 
Get URL path to the current database
When coding web applications, we're all familiar with the famous formula:
@ReplaceSubstring(@Subset(@DbName; -1); "\\" : " "; "/" : "+")
which will take the path to the current database and make it "browser-friendly".
(By the way, in R5 the formula language is now color-coded with keywords in blue, strings in magenta, etc. But we've noticed that "\\" isn't color-coded correctly, although it's compiled correctly. So we've gotten used to using @Char(92) in place of the double backslash so the color coding works out correctly).

In LotusScript, a similar subroutine can be written to perform the same task. This subroutine will get the correct path to the database and make sure the slashes go the right way and any spaces are replaced with plus signs. The best way to use this function is to put it in a script library which can be reused whenever you need it.

Here's the code...

Function GetDbName As String
   ' This function returns the URL version of the database name. For a local database (during
   ' testing), we just want the file name. For a server database (in production), we want the
   ' subdirectory and file name with the correct slashes
   Dim s As notessession
   Dim db As notesdatabase
   Dim dbname As String
   
   Set s = New notessession
   Set db = s.currentdatabase
   If Not s.isonserver Then
   ' Database is being used by a Notes client or by a browser on a local machine
      If db.server <> "" Then ' Database is on a server being used by a Notes client
         dbname = db.filepath
         While Instr(dbname, "\") <> 0
            dbname = Left(dbname, Instr(dbname, "\")-1) & "/" & Mid(dbname, Instr(dbname, "\")+1)
         Wend
         While Instr(dbname, " ") <> 0
            dbname = Left(dbname, Instr(dbname, " ")-1) & "+" & Mid(dbname, Instr(dbname, " ")+1)
         Wend
      Else ' Database is being used on a local machine (either by Notes client or browser)
         Dim directory As String
         directory = s.getenvironmentstring("Directory", True)
         dbname = db.filepath
         dbname = Mid(dbname, Instr(dbname, directory)+Len(directory)+1)
         While Instr(dbname, "\") <> 0
            dbname = Left(dbname, Instr(dbname, "\")-1) & "/" & Mid(dbname, Instr(dbname, "\")+1)
         Wend
         While Instr(dbname, " ") <> 0
            dbname = Left(dbname, Instr(dbname, " ")-1) & "+" & Mid(dbname, Instr(dbname, " ")+1)
         Wend
      End If
   Else ' Database is being used on a server by a browser
      dbname = db.filepath
      While Instr(dbname, "\") <> 0
         dbname = Left(dbname, Instr(dbname, "\")-1) & "/" & Mid(dbname, Instr(dbname, "\")+1)
      Wend
      While Instr(dbname, " ") <> 0
         dbname = Left(dbname, Instr(dbname, " ")-1) & "+" & Mid(dbname, Instr(dbname, " ")+1)
      Wend
   End If
   GetDbName = dbname
End Function