If using FileUp alone, you must submit any uploaded files through an HTML form. Outlook email messages need to be saved to disk first, then sent along as an upload request.
If using XFile, you have more options. Although XFile does not support drag-and-drop directly from Microsoft Outlook, it does support drag-and-drop from Windows Explorer, or it can be called from an Outlook VBA macro that invokes it silently to send the message in an upload request. This article will explain these methods of uploading email messages from Outlook using XFile and FileUp.
Although you cannot drag directly from Outlook, you can either:
- Instruct your users how to save their email messages to the file system and then drag to XFile from Windows Explorer.
- Automate the process of saving the file, instantiating XFile and posting the file to the webserver in a VBA macro.
To Manually Save a Message to the File System:
To make this process easier for your end-users, you can write a macro that will give the same end result. The macro can then be mapped to a toolbar button, so that the user only needs to click the button to upload an email message to the webserver.
- Open the message in it's own window (not the preview pane), by double-clicking on the message.
- From the new window, select File > Save and select a directory in which to save the message as either a *.msg file, *.htm file or a *.txt file.
- Open Windows Explorer. Locate the file, select it and drag the file onto XFile's visual control.
To Provide an Automated Email Upload with XFile with a VBA Macro for Outlook:
- Open Microsoft Outlook.
- Open Outlook's VBA editor and copy the following VBA code into your project.
- Add a shortcut for the macro to your Toolbar for the Explorer (viewing the list of all emails in your inbox) and Inspector (viewing an open email) screens by choosing
Tools > Customize > Commands tab for each screen. Select "Macro" in the "Categories" window, and drag the UploadCurrentMsg macro from the "Commands" window to the toolbar.
Now with either an email selected or an email opened for reading, you will have a shortcut available to you on the toolbar that will allow you to run the code that saves the message to disk, instantiates XFile and uploads the email to the webserver.
The VBA code:
Function GetCurrentItem() As Object
Set GetCurrentItem = Nothing
' Sections of GetCurrentItem()Courtesy of:
Dim objApp As Outlook.Application
Set objApp = CreateObject("Outlook.Application")
Select Case TypeName(objApp.ActiveWindow)
Dim lngSelected As Long
'---This code sample is only set up
'---to upload one selection at a time.
lngSelected = objApp.ActiveExplorer.Selection.Count()
If lngSelected > 1 Then
MsgBox "Only the first item selected will be uploaded."
Set GetCurrentItem = objApp.ActiveExplorer.Selection.Item(1)
Set GetCurrentItem = objApp.ActiveInspector.CurrentItem
Set objApp = Nothing
Dim o As MailItem
Set o = GetCurrentItem
'---Give the email message file a name based on it's subject line.
'---If the name is not unique on the server,
'---FileUp is set up to append a unique identifier to the name.
'---(see Response.asp -->CreateNewFile method)
Dim strName As String
strName = o.Subject
'---You will want to insert code here
'---that strips out illegal characters that are
'---allowable in a subject field,
'---but inappropriate for the file system, such as "!"
strName = strName & ".msg"
'---Save the file to the local temp directory so that
'---XFile can get a handle on it.
o.SaveAs "c:\Save Here\" & strName, olMSG
'---The following code assumes XFile is installed on the client
Dim XFile As Object
Set XFile = CreateObject("SoftArtisans.XFRequest")
'---Instantiate XFile to send an upload request to the server.
XFile.RequestMethod = "POST"
'---This is the URL to the server-side upload
'---processing script that instantiates FileUp
XFile.CurrentURL = "http://localhost" & _
'---Pick up the *.msg file that we just saved to the file system
XFile.AddFile "c:\Save Here\" & strName, "myFile_" & strName
'---Start the upload
'---Report the Response back from the server.
The server-side code (formresp.asp):
<%@ Language=VBScript %>
<% Option Explicit %>
'--- Instantiate the FileUp object
Set oFileUp = Server.CreateObject("SoftArtisans.FileUp")
'--- Set the Path property to the location you wish to
'--- temporarily cache the incoming file before saving
'--- Note: This property must be set immediately after
'--- instantiating the FileUp object
oFileUp.Path = "C:\Save Here2\"
'--- This will create a new file name
'--- if the uploaded file name is not unique
'--- For more information on this strategy:
oFileUp.CreateNewFile = True
Response.Write "Upload Results:" & chr(13)
Response.Write "Element type --- Element Name --- Value" & chr(13)
'--- This main loop will iterate through
'--- every submitted form element.Within the loop,
'--- we'll test it to see if it's a file
'--- or a text form element. If it's a text form element,
'--- we'll see if it's a single-value
'--- or a subcollection
For Each strFormElement In oFileUp.Form
'--- If it's a file, IsObject() will return True
'--- if it's a conventional form element, it will be False
If IsObject(oFileUp.Form(strFormElement)) Then
'--- It's a file element, is it empty?
If Not oFileUp.Form(strFormElement).IsEmpty Then
'--- It's not empty, so we'll save it
On Error Resume Next
If Err.Number <> 0 Then
Response.Write "An error occurred while saving the file." & _
Err.Description & " (" & Err.Source & ")"
On Error Goto 0
Response.Write "File " & strFormElement & " Saved as: " & _
oFileUp.Form(strFormElement).ServerName & " " & chr(13)
'--- It's empty, just write a message
Response.Write "File " & strFormElement & " (Empty) " & chr(13)
'--- If it's not a file, it's a conventional text-based form element
'--- It's a subcollection, we'll need to loop again
'--- to retrieve the values of the subcollection here
'--- Note how we need to use FormEx
'--- to determine if it's a subcollection
'--- always use FormEx when using,
'--- or if anticipating using, subcollections
If oFileUp.FormEx(strFormElement).Count > 1 Then
Response.Write "Subcollection " & strFormElement & " " & chr(13)
i = 1
'--- Loop through the subcollection
For Each strSubItem In oFileUp.FormEx(strFormElement)
Response.Write i & ": " & strSubItem & " " & chr(13)
i = i + 1
'--- It's just a single value, not a subcollection
'--- simply display the single value
Response.Write " Form single value " & strFormElement & " " & _
oFileUp.Form(strFormElement) & chr(13)
'--- Dereference FileUp
Set oFileUp = Nothing