Sunday, November 2, 2008

Convert a Notes DocLink to an URL


With the NotesRichTextNavigator to can search a richtext item and find all the DocLinks. With the NotesRichTextDoclink class it is easy to extract information about the link, e.g. servernavn, replicaid and document unid.
In this sample, I get the first DocLink in the 'Link' field and converts it to a Notes URL (notes://) - this is saved in a field called 'Link'
A more generic class to handle links can be found in the Developer Toolbox database (the NotesLink script library)

Sub Postsave(Source As Notesuidocument)
        Dim doc As NotesDocument

        Set doc = source.Document

       
        Dim rtf As NotesRichTextItem

        Dim rtNav As NotesRichTextNavigator

        Dim rtLink As NotesRichTextDoclink

        Dim server As NotesName

       
        Dim url As String

       
                Set rtf = doc.GetFirstItem( "link" )

                If rtf Is Nothing Then Goto DONE

               
                Set rtnav = rtf.CreateNavigator

                If rtnav.FindFirstElement( RTELEM_TYPE_DOCLINK ) Then

                        Set rtlink = rtnav.GetElement

                        Set server = New NotesName( rtLink.ServerHint )

                       
                        url = "notes://" & server.Common & "/" & rtLink.DBReplicaID

                       
                        If  rtlink.ViewUNID <> String$(32, "0") Then

                                url = url & "/" & rtLink.ViewUnID

                        End If

                       
                        If  rtlink.DocUNID <> String$(32, "0") Then

                                url = url & "/" & rtLink.DocUnID

                        End If

                       
                End If

       
DONE:

        If doc.url( 0 ) <> url Then

                doc.url = url

                Call doc.Save( True, False )

        End If

End Sub

0 comments:

 
Creative Commons License
This work is licensed under a Creative Commons Attribution 3.0 Unported License.