usmanazizgroupdocs
3/16/2016 - 8:15 AM

AddCollaborator.vb

' For complete examples and data files, please go to https://github.com/groupdocs-annotation/GroupDocs.Annotation-for-.NET
' Create instance of annotator. 
Dim cfg As AnnotationConfig = CommonUtilities.GetConfiguration()

Dim annotator As New AnnotationImageHandler(cfg)

Dim userRepository As IUserDataHandler = annotator.GetUserDataHandler()

Dim documentRepository As IDocumentDataHandler = annotator.GetDocumentDataHandler()
If Not Directory.Exists(cfg.StoragePath) Then
    Directory.CreateDirectory(cfg.StoragePath)
End If

' Create a user that will be an owner.           
' Get user from the storage 
Dim owner = userRepository.GetUserByEmail("john@doe.com")

' If user doesn’t exist in the storage then create it. 
If owner Is Nothing Then
    userRepository.Add(New User() With { _
        .FirstName = "John", _
        .LastName = "Doe", _
        .Email = "john@doe.com" _
    })
    owner = userRepository.GetUserByEmail("john@doe.com")
End If

' Get document data object in the storage
Dim document = documentRepository.GetDocument("Document.pdf")

' If document already created or it hasn’t owner then delete document
If document IsNot Nothing AndAlso document.OwnerId <> owner.Id Then
    documentRepository.Remove(document)
    document = Nothing
End If

' Get document id if document already created or create new document
Dim documentId As Long = If(document IsNot Nothing, document.Id, annotator.CreateDocument("Document.pdf", DocumentType.Pdf, owner.Id))

' Create reviewer. 
'user email, unique identifier
Dim reviewerInfo = New ReviewerInfo() With { _
    .PrimaryEmail = "judy@doe.com", _
    .FirstName = "Judy", _
    .LastName = "Doe", _
    .AccessRights = AnnotationReviewerRights.All _
}

' Add collaboorator to the document. If user with Email equals to reviewers PrimaryEmail is absent it will be created.