PreviousNext…

Tip #12: delete a local replica

The code

Nice and short this one. You just need to edit the constant at the top detailing the replica ID of the file to remove. I typically dump code like this in a button in a mail or whatever. It's a common request in our organisation, so maybe this will be of use to you too.


	Dim db As New NotesDatabase("", "")
	Dim strRepID As String
	Dim strMsg As String
	Dim strTitle As String
	Dim strPath As String

' // Replica ID of file to remove
' // (omit the colon in the middle)
	strRepID = "@@@@@@@@@@@@@@@@"

	Const SUCCESS = "Database successfully removed."
	Const NO_DB = "Halting: Couldn't find database to removed."

	If db.OpenByReplicaID("", strRepID) Then
' // Found Db, so grab its filepath and title
		strPath = db.FilePath
		strTitle = db.Title
		strMsg = "I've located the database to remove ('" &_
		strTitle & "'). Is this OK with you?"

		' // Set to Nothing so we can re-instantiate
		Set db = Nothing

		' // Instantiate once more, this time using
		' // file path derived above
		' // This way we can remove the db; the
		' // previous way we could not
		' // and we needed to use db.ReplicaID
		' // first time around
		Set db = New NotesDatabase("", strPath)
		If db.IsOpen Then
			' // Prompt YES / NO to removal
			If Messagebox(strMsg, 4, "Remove?") = 6 Then
				Call db.Remove()
				Messagebox SUCCESS, 0, "Complete"
				Exit Sub
			End If
		End If
		
	Else
		Messagebox NO_DB, 0, "Complete"
	End If

Comments

  1. It can't delete open databases - this I didn't this I was able to either, but It would have been a nice touch. When I shutdown the database and tryied again, I got the Red box telling my something had gone terribly wrong :-)) - nsd running etc.

    hmm…jk#

Comments on this post are now closed.

About

I’m a software architect / developer / general IT wrangler specialising in web, mobile web and middleware using things like node.js, Java, C#, PHP, HTML5 and more.

Best described as a simpleton, but kindly. You can read more here.

";