ShortFilename Property

Object: SoftArtisans.FileUp
Syntax: ShortFilename
Type: String
Read/Write: Read Only
Description:

This property returns the user's original name for the uploaded file, not including any path information.

For example, if a user uploads a file from the following path on their hard drive: "C:\MyFiles\filename.txt", the ShortFilename property will return "filename.txt".

This property can be used in conjunction with the SaveAs or SaveInVirtualmethods to save a file with the user's original user's filename in a directory otherthan the one used to temporarily cache the uploaded files (stored in the Path property ). The Save method, on the other hand, will automatically save a file with the user's original filename to the directory assigned to the path property. Using SaveAs or SaveInVirtual in conjunction with ShortFilename is especially useful when you wish to dynamically set the destination of the upload based on data passed from the upload form.

This property is also useful for storing filenames in a database.

If there is more than one file being uploaded in a single page, only the first one is displayed.

To examine the ShortFilename of multiple files in a single upload, there is an equivalent property for each file object, i.e., fileUpload.Form("File1").ShortFilename.

See the ShortFilename property of the SAFile object.

Note: The ShortFilename property is only implemented on IIS4 or higher.
Examples:

Output filename to user:

ASP The file you uploaded was: <%=fileUpload.ShortFilename%>.
C# results.Append("The file you uploaded was: " +
fileUpload.ShortFilename);
VB.NET results.Append("The file you uploaded was: " + _
fileUpload.ShortFilename)

Save file using original filename to directory chosen by the user:

ASP <%
'--- Create an instance of SoftArtisans FileUp
Set fileUpload = Server.CreateObject("SoftArtisans.FileUp")

'---Set the default path to store uploaded files
fileUpload.Path = "C:\Temp"

'--- Retrieve the user's chosen directory from the form
Dim newPath
newPath = fileUpload.Form("Directory")

'--- Save the file with the user's original filename
'--- to the user's chosen directory
fileUpload.SaveAs newPath & "\" & fileUpload.ShortFilename
%>
C# //--- Create an instance of SoftArtisans FileUp
FileUp fileUpload As New FileUp(Context);

//---Set the default path to store uploaded files
fileUpload.Path = @"C:\Temp";

//--- Retrieve the user's chosen directory from the form
string newPath = fileUpload.Form("Directory");

//--- Save the file with the user's original filename
//--- to the user's chosen directory
fileUpload.SaveAs(newPath & "\\" & fileUpload.ShortFilename);
VB.NET '--- Create an instance of SoftArtisans FileUp
Dim fileUpload As New FileUp(Context)

'---Set the default path to store uploaded files
fileUpload.Path = "C:\Temp"

'--- Retrieve the user's chosen directory from the form
Dim newPath As String = fileUpload.Form("Directory")

'--- Save the file with the user's original filename
'--- to the user's chosen directory
fileUpload.SaveAs(newPath + "\" + fileUpload.ShortFilename)

Copyright © 2010 SoftArtisans, Inc. All rights reserved.