Share via


Launching Attachments

The GetStream and ReplaceAttachment methods let you read the contents of an attachment and update the contents of an attachment. This provides the underlying functionality that enables your tool add-in to let a user update the contents of the attachment using a launched application. But the Add-in API does not provide any higher-level launch functionality.

The AttachmentsAndConflicts sample provided in the SDK provides a simple implementation of a launch and update capability. When the user double-clicks an attachment, the sample does the following:

  1. Queries the user if it discovers that the attachment contents are old.

  2. Checks that the attachment has contents and gets the contents as a stream.

  3. Writes the contents of the stream to a temporary file that has a generated file name together with the attachment file extension.

  4. Uses a FileSystemWatcher object to watch for updates to the file.

  5. Creates a new Process object and uses a shell execute on the file.

  6. When the user finishes editing the file, it uses the contents of the updated file to update the attachment.

Most of the work in developing a production-quality implementation of launch is in the last step, determining when the user has finished editing the file. Describing the details required for such an implementation is beyond the scope of this document, but you must deal with the following concerns:

  • Determining when the user has finished editing the attachment can be different depending on the application that is used to edit the application.

  • If the user closes the workspace or exits from SharePoint Workspace before finishing the update, the add-in code will not be executing when the update is finished. To handle this situation, your add-in could persist information when a file is launched and remove that information when the user has finished editing the file. It should check whether any file was launched but the edit was not finished when OnToolStart is called.