Does anyone have a sample where when a user sends an email from outlook a question is asked "Do you want to save to M-files? Yes or No"
If the user clicks yes the save/properties window is displayed
;D
Option Explicit
' Triggered when an e-mail is sent.
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
' Error handling.
On Error GoTo ErrorHandling
' Test and get an interface to the email item.
If Not TypeOf Item Is Outlook.MailItem Then
Exit Sub
End If
Dim emailItem As Outlook.MailItem
Set emailItem = Item
' Prompt for save.
If MsgBox("Save the message to M-Files?", vbYesNo Or vbMsgBoxSetForeground) = vbNo Then
Exit Sub
End If
' Get the M-Files client application interface and the vault connection.
' Note: fixed vault name.
Dim clientApp As New MFilesAPI.MFilesClientApplication
Dim vaultConnection As MFilesAPI.vaultConnection
Set vaultConnection = clientApp.GetVaultConnection("Sample")
' Bind and log in to the vault.
Dim vault As MFilesAPI.vault
Set vault = vaultConnection.BindToVault(0, True, True)
If vault Is Nothing Then GoTo Cancelled
' Create file classes for supported file formats.
Dim objectFileClasses As New MFilesAPI.FileClasses
objectFileClasses.Add -1, New MFilesAPI.FileClass
objectFileClasses(1).LoadByExtension "msg"
' Build ObjectCreationInfo for the metadata card with file class selector.
' In order to keep this simple, pretty much all editing is denied.
Dim objCreationInfo As New MFilesAPI.objectCreationInfo
objCreationInfo.SetTitleAsDatatypeText emailItem.Subject, True
objCreationInfo.SetObjectType MFilesAPI.MFBuiltInObjectTypeDocument, False
objCreationInfo.SetSingleFileDocument True, False
objCreationInfo.SetSelectableFileClasses objectFileClasses
objCreationInfo.SetSelectedFileClass objectFileClasses(1), False
objCreationInfo.SetExtension "msg", False
' Disable object creation because we will create it by ourselves later.
objCreationInfo.SetDisableObjectCreation True
' Display the metadata card for new object
Dim objWindowResult As MFilesAPI.objectWindowResult
Set objWindowResult = vault.ObjectOperations.ShowNewObjectWindow( _
0, MFObjectWindowModeInsertSaveAsType, objCreationInfo)
If objWindowResult.result = MFObjectWindowResultCodeCancel Then GoTo Cancelled
' Create new single-file document with empty file.
' Use properties provided by the metadata card to fill the object's metadata.
Dim objVersionAndProperties As MFilesAPI.objectVersionAndProperties
Set objVersionAndProperties = vault.ObjectOperations.CreateNewEmptySingleFileDocument( _
objWindowResult.Properties, _
objWindowResult.Properties.SearchForProperty(MFBuiltInPropertyDefNameOrTitle).GetValueAsUnlocalizedText, _
objWindowResult.SelectedFileClass.Extension)
' Resolve the path to the newly-created empty document file.
Dim path As String
Let path = vault.ObjectFileOperations.GetPathInDefaultView( _
objVersionAndProperties.ObjVer.ObjID, _
objVersionAndProperties.ObjVer.Version, _
objVersionAndProperties.VersionData.Files(1).FileVer.ID, _
objVersionAndProperties.VersionData.Files(1).FileVer.Version)
' Save the e-mail over the empty file.
emailItem.SaveAs path
' Check in right away, unless we are in offline mode.
If vault.ClientOperations.IsOnline Then
vault.ObjectOperations.CheckIn objVersionAndProperties.ObjVer
End If
Exit Sub
' Error handling.
ErrorHandling:
MsgBox Err.Description
Exit Sub
' Cancellation.
Cancelled:
Cancel = True
emailItem.Display
Exit Sub
End Sub
Option Explicit
' Triggered when an e-mail is sent.
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
' Error handling.
On Error GoTo ErrorHandling
' Test and get an interface to the email item.
If Not TypeOf Item Is Outlook.MailItem Then
Exit Sub
End If
Dim emailItem As Outlook.MailItem
Set emailItem = Item
' Prompt for save.
If MsgBox("Save the message to M-Files?", vbYesNo Or vbMsgBoxSetForeground) = vbNo Then
Exit Sub
End If
' Get the M-Files client application interface and the vault connection.
' Note: fixed vault name.
Dim clientApp As New MFilesAPI.MFilesClientApplication
Dim vaultConnection As MFilesAPI.vaultConnection
Set vaultConnection = clientApp.GetVaultConnection("Sample")
' Bind and log in to the vault.
Dim vault As MFilesAPI.vault
Set vault = vaultConnection.BindToVault(0, True, True)
If vault Is Nothing Then GoTo Cancelled
' Create file classes for supported file formats.
Dim objectFileClasses As New MFilesAPI.FileClasses
objectFileClasses.Add -1, New MFilesAPI.FileClass
objectFileClasses(1).LoadByExtension "msg"
' Build ObjectCreationInfo for the metadata card with file class selector.
' In order to keep this simple, pretty much all editing is denied.
Dim objCreationInfo As New MFilesAPI.objectCreationInfo
objCreationInfo.SetTitleAsDatatypeText emailItem.Subject, True
objCreationInfo.SetObjectType MFilesAPI.MFBuiltInObjectTypeDocument, False
objCreationInfo.SetSingleFileDocument True, False
objCreationInfo.SetSelectableFileClasses objectFileClasses
objCreationInfo.SetSelectedFileClass objectFileClasses(1), False
objCreationInfo.SetExtension "msg", False
' Disable object creation because we will create it by ourselves later.
objCreationInfo.SetDisableObjectCreation True
' Display the metadata card for new object
Dim objWindowResult As MFilesAPI.objectWindowResult
Set objWindowResult = vault.ObjectOperations.ShowNewObjectWindow( _
0, MFObjectWindowModeInsertSaveAsType, objCreationInfo)
If objWindowResult.result = MFObjectWindowResultCodeCancel Then GoTo Cancelled
' Create new single-file document with empty file.
' Use properties provided by the metadata card to fill the object's metadata.
Dim objVersionAndProperties As MFilesAPI.objectVersionAndProperties
Set objVersionAndProperties = vault.ObjectOperations.CreateNewEmptySingleFileDocument( _
objWindowResult.Properties, _
objWindowResult.Properties.SearchForProperty(MFBuiltInPropertyDefNameOrTitle).GetValueAsUnlocalizedText, _
objWindowResult.SelectedFileClass.Extension)
' Resolve the path to the newly-created empty document file.
Dim path As String
Let path = vault.ObjectFileOperations.GetPathInDefaultView( _
objVersionAndProperties.ObjVer.ObjID, _
objVersionAndProperties.ObjVer.Version, _
objVersionAndProperties.VersionData.Files(1).FileVer.ID, _
objVersionAndProperties.VersionData.Files(1).FileVer.Version)
' Save the e-mail over the empty file.
emailItem.SaveAs path
' Check in right away, unless we are in offline mode.
If vault.ClientOperations.IsOnline Then
vault.ObjectOperations.CheckIn objVersionAndProperties.ObjVer
End If
Exit Sub
' Error handling.
ErrorHandling:
MsgBox Err.Description
Exit Sub
' Cancellation.
Cancelled:
Cancel = True
emailItem.Display
Exit Sub
End Sub