Home     Products      Support      Corporate     Sign In 
Support Knowledge Base, Article 640
Product
FileUp
Title
How to determine the filename of the uploaded file after it has been saved on the server
Problem
FileUp provides the SeverName property to return the complete physical path of the location to which an uploaded file was saved. To return only the filename, simple string parsing functions may be used on this value.
Solution

To extract the filename as the file was saved to the server, string parsing functions may be applied to the value returned by the ServerName property. This may be useful if the name of the file is expected to be changed before it is saved, such as with the CreateNewFile property of the FileUp object. The following sample demonstrates how the server-side filename can be determined.

     '--- Declarations
     Dim oFileUp
     Dim strServerName
     Dim strFileName

     '--- 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:\SaveHere"

     '--- Instruct FileUp to generate a unique file name if the
     '--- file's original name already exists on the server.
     '--- Important: Set CreateNewFile before referencing form elements.
     oFileUp.CreateNewFile = True

     '--- Check to be sure there was a file selected in the form
     '--- If so, continue processing
     If Not oFileUp.Form("myFile").IsEmpty Then

       '--- Save the file
       oFileUp.Form("myFile").Save

       '--- The ServerName() property is the full path of the file
       '--- where it was saved on the server
       strServerName = oFileUp.Form("myFile").ServerName

       '---Extract the filename from the complete path
       strFileName = Mid(strServerName, InstrRev(strServerName, "\") + 1)

       '--- The file is saved, display a confirmation message
       Response.Write("<B>File saved successfully on the server as: " & _          strFileName & "</B><BR>")

     Else
       Response.Write ("Error: There was no file submitted for upload.")
     End If

     '--- Destroy objects
     Set oFileUp = Nothing
Created : 7/18/2003 1:42:50 PM (last modified : 7/18/2003 1:42:47 PM)
Rate this article!
Comments