Home     Products      Support      Corporate     Sign In 
Support Knowledge Base, Article 965
Product
XFile
Version
all versions
Title
Can I upload directly from Microsoft Outlook?
Problem

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.

Solution

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:

  1. Open the message in it's own window (not the preview pane), by double-clicking on the message.
  2. 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.
  3. Open Windows Explorer. Locate the file, select it and drag the file onto XFile's visual control.

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.

To Provide an Automated Email Upload with XFile with a VBA Macro for Outlook:

  1. Open Microsoft Outlook.
  2. Open Outlook's VBA editor and copy the following VBA code into your project.
  3. 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:
  ' http://www.outlookcode.com/codedetail.aspx?id=50
  Dim objApp As Outlook.Application

  Set objApp = CreateObject("Outlook.Application")
  Select Case TypeName(objApp.ActiveWindow)
    Case "Explorer"
      'MsgBox "Explorer"

      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."
      End If

      Set GetCurrentItem = objApp.ActiveExplorer.Selection.Item(1)

    Case "Inspector"
      'MsgBox "Inspector"
      Set GetCurrentItem = objApp.ActiveInspector.CurrentItem
    Case Else
      'MsgBox "Else"
  End Select

  Set objApp = Nothing
End Function


Sub UploadCurrentMsg()
  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" & _
  "/WORK-WEB/NEW%20SAMPLES/XFILE/OutlookToXFile/formresp.asp"

  '---Pick up the *.msg file that we just saved to the file system
  XFile.AddFile "c:\Save Here\" & strName, "myFile_" & strName

  '---Start the upload
  XFile.Start

  '---Report the Response back from the server.
  MsgBox XFile.Response

End Sub

The server-side code (formresp.asp):

<%@ Language=VBScript %>
<% Option Explicit %>
<%

  '--- Declarations
  Dim oFileUp
  Dim strFormElement
  Dim strSubItem
  Dim i

  '--- 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:
  '--- http://support.softartisans.com/kbview.aspx?ID=691
  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
          oFileUp.Form(strFormElement).Save

          If Err.Number <> 0 Then
            Response.Write "An error occurred while saving the file." & _
            Err.Description & " (" & Err.Source & ")"
            Response.End
          End If

          On Error Goto 0
          Response.Write "File " & strFormElement & " Saved as: " & _           oFileUp.Form(strFormElement).ServerName & " " & chr(13)
        Else

          '--- It's empty, just write a message
          Response.Write "File " & strFormElement & " (Empty) " & chr(13)
        End If

    '--- If it's not a file, it's a conventional text-based form element
    Else
      '--- 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
        Next
      Else

        '--- 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)
      End If

    End If

  Next

  '--- Dereference FileUp
  Set oFileUp = Nothing
%>

Created : 1/28/2005 2:51:55 PM (last modified : 1/28/2005 2:51:55 PM)
Rate this article!
Comments