Home     Products      Support      Corporate     Sign In 
Support Knowledge Base, Article 808
Product
FileUp
Title
Accessing the uploaded file as an array of variants
Problem

FileUp's UploadContents property can return the contents of an uploaded file as a safe array of variants, which is the only type of array suitable for the ASP scripting environment. The code sample below demonstrates how to access the contents of an uploaded *.txt file through this type of array.

Note: It is normally preferable to access the contents of a *.txt file through a variant of the type "string", however, for the sake of demonstrating the storage structure of a variant array, we've choosen to upload a simple text file so that ASP's Response.Write method can return human-readable characters to the browser.

Solution
<% '--- Declarations
Dim oFileUp

'--- Instantiate the FileUp object
Set oFileUp = Server.CreateObject("SoftArtisans.FileUp")
oFileUp.UseMemory = true

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

  Dim mySafeArray
  mySafeArray = oFileUp.Form("myFile").uploadContents(1)
  '--returns safe array of variants
  '--Because we are intentionally uploading a simple *.txt file,
  '--the ANSI character code for each character in the file
  '--becomes an individual member of the variant array.

  Dim x
  for x= LBound(mySafeArray) to UBound(mySafeArray)
    '--convert the ansi character code with the chr() function
    Response.Write chr(mySafeArray(x))
  next

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

'--- Destroy objects
Set oFileUp = Nothing
%>


Related Links:

Created : 3/4/2004 4:01:37 PM (last modified : 3/4/2004 4:01:37 PM)
Rate this article!
Comments