Send A View To Another User (Part 2)Recently an end user of ours created a private view that another end user wanted. These end users wanted to know if there was a way to "send a view" from one user to another. Our administrator told the user to get on the phone and describe the design of their view while the other user created their private view. Is there a better way?
In Notes 6, you could switch a view from private to public so it could then be copied/pasted and switched back to private. But that would assume both users have designer access to the database. A better way is using the NotesDXL classes available in Notes 6. In part 1 of this tip, we showed you how to choose a view in the current database and export it to a DXL file. Now in part 2, we'll show you how to take that DXL file and import it into a new database.
This processing is handled through agents. Right now the agents assume the current database (so the agent needs to be in the "view to be copied" database). It wouldn't be that difficult to modify the agent so it's in a centralized place and the user chooses the source database.
This agent works by prompting the user for the source DXL file. This is the file that was created in part 1 of this tip. That DXL file is processed, which builds whatever the DXL tells it to build in the destination (current) database. In our case, the DXL describes one and only one view, so that is what is built in the destination.
Here's the code:
Dim ws As New NotesUIWorkspace
Dim session As New NotesSession
Dim dataDir As String
Dim fileName As Variant
Dim db As NotesDatabase
Dim stream As NotesStream
Dim importer As NotesDXLImporter
dataDir = session.GetEnvironmentString("Directory", True)
fileName = ws.OpenFileDialog(False, "Choose Source File", "DXL Files|*.dxl", dataDir)
If fileName(0) = "" Then Exit Sub
Set db = session.CurrentDatabase
Set stream = session.CreateStream
If Not stream.Open(fileName(0)) Then Exit Sub
Set importer = session.CreateDXLImporter(stream, db)
importer.DesignImportOption = DXLIMPORTOPTION_CREATE
First, let me point out a couple of things with this code. First, the user is prompted with the file. They start out in their Notes Data directory and can only choose files with a .DXL extension. This matches what was created in part 1. Second, the DXL importer uses a NotesStream object as its input (the stream points to the file on the file system) and a NotesDatabase object (the current database) as its output (where the design element will be created). There are options in the NotesDXLImporter class that say what to do with the "stuff" in the DXL file and how to handle things like duplicate design elements. Here, we want to create the new private view. Finally, the Process method actually creates the design element.
If you look at part 1 and part 2 of our code, you have a complete set of agents to copy a standard view from one database to another. Our real request came from copying a private view from one user to another. This code needs to be modified if that's your ultimate goal. First, if you look back in part 1 you'll probably only want the user to be able to choose private views (right now it defaults to all the views in the database). But the second part is more important. If you use the agent from part 1 and look at the DXL that is created, near the bottom of the DXL you'll notice two items:
<item name='$Readers' sign='true' readers='true'><text>CN=Some Name/OU=Some Organization/O=Your Company</text></item>
<item name='$Authors' sign='true' authors='true'><text>CN=Some Name/OU=Some Organization/O=Your Company</text></item>
Private views are design elements that are secured through readers and authors fields to the person who created the view. If you leave those in the DXL, the other person will be able to create the private view, but they won't be able to see it (because it will have the other person's notes id associated with it). So those lines have to be removed from the DXL file before it is sent to the other person. The code we use internally does that, but we're not giving away all our secrets here.
The last thing to point out is that this agent to build the view honors Notes ACL. If the DXL says that a public view is to be built, the user needs to have "Create Shared Folders/Views" enabled in the ACL. For our implementation, we needed users to have "Create Personal Folders/Views" enabled in the ACL. The DXL itself provides information about the view. Here's part of a line of the DXL when a private view is exported:
<view name='My Private View' ... private='true' ...>
So the DXL says that it's a private view, which is the type of design element it will create.