SAFile



This class serves the general purpose functions of the file.  This class can be instantiated  independent to the  FileUp  and its functions can be invoked even when there is no upload in progress.


    Example:
    <% Set obj= Server.CreateObject("SoftArtisans.SAFile") %>




 METHODS:
 


 PROPERTIES:
 




DESCRIPTION OF METHODS


Method Signature:  void create([in]String   fullyQualifiedFilename)

This method creates the required file on the Server. The filename should be given with fully qualified path, otherwise the file is created in the default directory ( here the user's current working directory). If the file of the same name already exists, then 'create' method overwrites it.

Example:
(for creating files)

Script for 'createSample.asp':

         <HTML><HEAD>
        <TITLE>Upload File </TITLE>
        </HEAD>
        <BODY>
        <%
        Set obj = Server.CreateObject("SoftArtisans.SAFile")
        obj.create "\MyFolder1\MyFolder2\MyHtml.html"
        obj.Path= "c:\program files\plus!"
        obj.create "MyHtml.html"
        %>
        <BR>
        Thank you for uploading your file.
        </BODY>
        </HTML>




Method Signature:  void createtemp()

This method creates the temporary file on the Server.  By default the files are created in the current user's working directory. The path property can be used to create these files in the desired directory. The temporary files aquire the names Iasp_#1.tmp, Iasp_#2.tmp, Iasp_#3.tmp and so on.
 

Example:
(for creating temporary files)

Script for 'tempSample.asp':

         <HTML><HEAD>
        <TITLE>Upload File </TITLE>
        </HEAD>
        <BODY>
        <%
        Set obj = Server.CreateObject("SoftArtisans.SAFile")
        obj.createTemp
        obj.createTemp
        obj.Path= "c:\program files"
        obj.createTemp
        %>
        <BR>
        Thank you for uploading your file.
        </BODY>
        </HTML>

The above program creates two temporary files in the current working directory and the third temporary file in the desired directory.




Method Signature:  void saveAs([in]String   filename)

This method  uploads the browsed file with the given filename on the Server. If the path property is not set, then the file(s) will be saved in the current working directory of the Server. Any relative path given in the filename argument shall get concatenated with the path property. It should be noticed that the path where a file is being uploaded should exist on the Server.

Example:
(for single file upload)

Html page:

      <HTML>  <HEAD>
        <TITLE>File Upload via SAFile</TITLE>
        </HEAD>
        <BODY>
        <form enctype="multipart/form-data" method="post" action="sample2.asp">
        Enter filename to upload: <input type="file" name="file1"><br>
        <input type="submit">
        </form>
        </BODY>
        </HTML>

Script for 'sample2.asp':

     <HTML><HEAD>
        <TITLE>Upload File </TITLE>
        </HEAD>
        <BODY>
        <% Set obj = Server.CreateObject("SoftArtisans.SAFile")
         obj.Path ="c:\temp"
        obj.saveAs "MyHtml.html" %><BR>
        Thank you for uploading your file.
        </BODY>
        </HTML>

If multiple files are to be uploaded by a single request (i.e. by clicking the Submit button), then 'form' method is used. In this case, all the information related to files remain saved in the UploadDictionary object and the files can be accessed again with all their properties.

Example:
( for multiple files upload)

Script for 'sample2.asp':

        <HTML><HEAD>
        <TITLE>Uploading Multiple Files </TITLE>
        </HEAD>
        <BODY>
        <% Set obj = Server.CreateObject("SoftArtisans.SAFile")
         obj.Path= "c:\temp"
         obj.form("file1").saveAs "MyHtml01.html"
         obj.form("file2").saveAs "MyHtml02.html"
         obj.form("file3").saveAs "MyHtml03.html"
        <BR>
        Thank you for uploading your file.
        </BODY>
        </HTML>

In case file of the same name already exists, 'saveAs' method overwrites it by default.




Method Signature:  void save()

This method  uploads the browsed file with the original filename on the Server.

Example:
(for single file upload)

Html page:

         <HTML>  <HEAD>
        <TITLE>File Upload via SAFile</TITLE>
        </HEAD>
        <BODY>
        <form enctype="multipart/form-data" method="post" action="sample2.asp">
        Enter filename to upload: <input type="file" name="file1"><br>
        <input type="submit">
        </form>
        </BODY>
        </HTML>

Script for 'sample2.asp':

        <HTML><HEAD>
        <TITLE>Upload File </TITLE>
        </HEAD>
        <BODY>
        <% Set obj = Server.CreateObject("SoftArtisans.SAFile")
         obj.Path ="c:\temp"
        obj.save %><BR>
        Thank you for uploading your file.
        </BODY>
        </HTML>

If multiple files are to be uploaded by a single request (i.e. by clicking the Submit button), then 'form' method is used. In this case, all the information related to files remain saved in the UploadDictionary object and the files can be accessed again with all their properties.

Example:
( for multiple files upload)

Script for 'sample2.asp':

      <HTML><HEAD>
        <TITLE>Uploading Multiple Files via SAFile</TITLE>
        </HEAD>
        <BODY>
        <% Set obj = Server.CreateObject("SoftArtisans.SAFile")
         obj.Path ="c:\temp"
         obj.form("file1").save
         obj.form("file2").save
         obj.form("file3").save
        <BR>
        Thank you for uploading your file.
        </BODY>
        </HTML>

In case file of the file having similar name already exists, 'save' method overwrites it.




Method Signature:  void saveInVirtual()

This method  uploads the browsed file with the original filename on the Server's virtual directory.

Example:
(for single file upload in Virtual Directory)

Html page:

         <HTML>  <HEAD>
        <TITLE>File Upload via SAFile</TITLE>
        </HEAD>
        <BODY>
        <form enctype="multipart/form-data" method="post" action="sample2.asp">
        Enter filename to upload: <input type="file" name="file1"><br>
        <input type="submit">
        </form>
        </BODY>
        </HTML>

Script for 'sample2.asp':

        <HTML><HEAD>
        <TITLE>Upload File </TITLE>
        </HEAD>
        <BODY>
        <% Set obj = Server.CreateObject("SoftArtisans.SAFile")
        obj.saveInVirtual %><BR>
        Thank you for uploading your file.
        </BODY>
        </HTML>

If multiple files are to be uploaded by a single request (i.e. by clicking the Submit button), then 'form' method is used. In this case, all the information related to files remain saved in the UploadDictionary object and the files can be accessed again with all their properties.

Example:
( for multiple files upload in Virtual Directory)

Script for 'sample2.asp':

         <HTML><HEAD>
        <TITLE>Uploading Multiple Files via SAFile</TITLE>
        </HEAD>
        <BODY>
        <% Set obj = Server.CreateObject("SoftArtisans.SAFile")
         obj.form("file1").saveInVirtual
         obj.form("file2").saveInVirtual
         obj.form("file3").saveInVirtual
        <BR>
        Thank you for uploading your file.
        </BODY>
        </HTML>

In case file of the file having next name already exists, 'saveInVirtual' method overwrites it by default.




Method Signature:  void saveAsBlob([in] ADODB.FIELD  columnNameOfTable)

This method saves the browsed file into the Database. The recordset must point to a valid ADO Field object.

For Microsoft SQL Server, the column should be 'image' type while for Microsoft Access, the column should be 'OLE Object'.

When saving into blob fields, the ADO Recordset's cursor type should be equal to 2 and lock type should be 3.

Example:
( for single file uploading in database)

Html page:

      <HTML>  <HEAD>
        <TITLE>Single File Save to the DataBase via iASP_Fileup</TITLE>
        </HEAD>
        <BODY>
        <form enctype="multipart/form-data" method="post" action="sample3.asp">
        Enter filename to upload: <input type="file" name="file1"><br>
        <input type="submit">
        </form>
        </BODY>
        </HTML>

Script for 'ScriptBlob.asp':

     <HTML><HEAD>
        <TITLE>Saving Single Files </TITLE>
        </HEAD>
        <BODY>
        <%
        Set obj = Server.CreateObject("SoftArtisans.FileUp")
        Set rsBlob = Server.CreateObject("ADODB.RECORDSET")
        rsBlob.Open "TableName", "DSN", 2, 3    ' Table Name, DatabaseSourceName,Cursor Type, Lock Type
        rsBlob.AddNew
        obj.saveAsBlob rsBlob.Fields("columnNameOfTable")
        rsBlob.Update
        rsBlob.Close
        Set rsBlob = Nothing
        %>
        <BR>
        Thank you for uploading your file.
        </BODY>
        </HTML>

If multiple files are to be uploaded by a single request (i.e. by clicking the Submit button), then 'form' method is used. In this case, all the information related to files remain saved in the UploadDictionary object and the files can be accessed again with all their properties.

Example:
( for multiple files upload in Database)

Script for direct 'ScriptBlob.asp':

        <HTML><HEAD>
        <TITLE>Saving Multiple Files </TITLE>
        </HEAD>
        <BODY>
        <%
        Set obj = Server.CreateObject("SoftArtisans.FileUp")
        Set rsBlob = Server.CreateObject("ADODB.RECORDSET")
        count=0
        rsBlob.Open "TableName", "DSN", 2, 3    ' Table Name, DatabaseSourceName,Cursor Type, Lock Type

        rsBlob.AddNew
        rsBlob.Fields("index").value = 1
        obj.form("file1").saveAsBlob rsBlob.Fields("columnNameOfTable")
        rsBlob.Update

        rsBlob.AddNew
        rsBlob.Fields("index").value = 2
        obj.form("file2").saveAsBlob rsBlob.Fields("columnNameOfTable")
        rsBlob.Update

        rsBlob.Close
        Set rsBlob = Nothing
        %>
        <BR>
        Thank you for uploading your file.
        </BODY>
        </HTML>




Method Signature:  void delete()
Method Signature:  void delete([in]String filename)

This method deletes the last uploaded file on the Server. If any specific file is to be deleted, then the name of that file is passed in to the overloaded delete method . This method can be used to cancel the last upload.

Example:
(for deleting last uploaded file)

Script of 'LastUploadDelete.asp':

       <HTML><HEAD>
        <TITLE>Saving Multiple Files via SAFile</TITLE>
        </HEAD>
        <BODY>
      <%
        Set obj= Server.CreateObject("SoftArtisans.SAFile")
         obj.save
         obj.save
         obj.save
         obj.delete  ' i.e. Cancelling the last upload
         %>
        <BR>
        Thank you for uploading your file.
        </BODY>
        </HTML>

Example:
(for deleting specific file)

Script of 'SpecificDelete.asp':

      <HTML><HEAD>
       <TITLE>Saving Multiple Files via SAFile</TITLE>
        </HEAD>
        <BODY>
        <% Set obj = Server.CreateObject("SoftArtisans.FileUp")
         obj.save
         obj.save
         obj.delete "c:\Program Files\Plus!\index.html"
         obj.save
        %>
        <BR>
        Thank you for uploading your file.
        </BODY>
        </HTML>




Method Signature:  void flush()

This method flushes the entire HTTP POST input stream. This method is used to explicitly clear the input stream especially, when a file greater than MaxBytes is sent. In this case,the browser wants to send more data and in due course, invokes Network Error. This error is never displayed as the browser assumes that the request was never completed. Thus the 'flush' method can be used to explicitly clear the input stream.

Example:
(for flushing the HTTP POST inputstream)

Script of 'flushSample.asp':

     <HTML><HEAD>
        <TITLE>Flushing Input Stream via SAFile</TITLE>
        </HEAD>
        <BODY>
          <%
        Set obj= Server.CreateObject("SoftArtisans.SAFile")
        obj.save    'file greater than MaxBytes is uploaded
        obj.flush    'clears the inputstream
        %>
        </BODY>
        </HTML>






DESCRIPTION OF PROPERTIES
 


Property Name: ContentType

This is a Read-Only property. The  MIME Content Type of the file (specified by the fieldName), is used to  determine the contents of the file. If multiple files are uploaded, then the ContentType of each file can be got by calling obj.form("file1").ContentType for each file upload. If obj.ContentType is called, it will return the ContentType of the first uploaded file.

Example:
(getting ContentType for multiple file upload)

<%
    con1 = obj.form("file1").ContentType
    con2 = obj.form("file2").ContentType
    con3 = obj.form("file3").ContentType
%>




Property Name: ContentDisposition

This is a Read-Only property. The MIME Content Disposition of the data should always be "form-data" when using a browser supporting RFC 1867 uploads. It is true for multiple file uploads also. If multiple files are uploaded, then the ContentDisposition of each file can be got by calling obj.form("file1").ContentDisposition for each file upload. If obj.ContentDisposition is called, it will return the ContentDisposition of the first uploaded file.

Example:
(getting ContentDisposition for multiple file upload)

<%
    disp1 = obj.form( "file1").ContentDisposition
    disp2 = obj.form( "file2").ContentDisposition
%>




Property Name:  Path

This is a Read/Write property. This property is used to set the destination path on the Server of the uploaded file. By default, the path is set to user current  working directory.

Example:
(setting path for multiple files upload)

Html page:

         <HTML>  <HEAD>
        <TITLE>Multiple File Upload via SAFile</TITLE>
        </HEAD>
        <BODY>
        <form enctype="multipart/form-data" method="post" action="sample2.asp">
        Enter filename to upload: <input type="file" name="file1"><br>
        Enter filename to upload: <input type="file" name="file2"><br>
        Enter filename to upload: <input type="file" name="file3"><br>
        <input type="submit">
        </form>
        </BODY>
        </HTML>

Script for 'sample2.asp':

        <HTML><HEAD>
        <TITLE>Uploading Multiple Files </TITLE>
        </HEAD>
        <BODY>
        <%
        Set obj= Server.CreateObject("SoftArtisans.SAFile")
        obj.Path ="c:\Program Files"
        obj.form("file1").saveAs "MyHtml01.html"
        obj.form("file2").save
        obj.form("file3").save
        %>
        <BR>
        Thank you for uploading your file.
       </BODY>
       </HTML>

In the above exampe, all the three files are uploaded in the c:\Program Files. Once the path is set, all the following files will be saved in the set path.




Property Name:  ServerName

This is a Read-Only property. ServerName is the fully qualified path where the file is saved on the Server. If multiple files are uploaded, then the ServerName of each file can be got by calling obj.form("file1").ServerName for each file upload. If obj.ServerName is called, it will return the ServerName of the first uploaded file.

Example:
(getting ServerName for multiple file upload)

Html page:

         <HTML>  <HEAD>
        <TITLE>Multiple File Upload via SAFile</TITLE>
        </HEAD>
        <BODY>
        <form enctype="multipart/form-data" method="post" action="sample2.asp">
        Enter filename to upload: <input type="file" name="file1"><br>
        Enter filename to upload: <input type="file" name="file2"><br>
        Enter filename to upload: <input type="file" name="file3"><br>
        <input type="submit">
        </form>
        </BODY>
        </HTML>
 

Script for 'sample2.asp':

     <%
        Set obj= Server.CreateObject("SoftArtisans.SAFile")
        obj.save
        obj.saveAs "MyHtml.html"
        obj.saveInVirtual
        server1 = obj.form("file1").ServerName
        server2 = obj.form("file2").ServerName
        server3 = obj.form("file3").ServerName

        Response.Write server1
        Response.Write server2
        Response.Write server3
        %>




Property Name: UserFileName

This is a Read-Only property. UserFileName is the fully qualified path of the file to be uploaded (according to the user's directory structure). If multiple files are uploaded, then the UserFileName of each file can be got by calling obj.form("file1").UserFileName for each file upload. If obj.UserFileName is called, it will return the UserFileName of the last uploaded file.

Example:
(getting UserFileName for multiple file upload)

Html page:

         <HTML>  <HEAD>
        <TITLE>Multiple File Upload via SAFile</TITLE>
        </HEAD>
        <BODY>
        <form enctype="multipart/form-data" method="post" action="sample2.asp">
        Enter filename to upload: <input type="file" name="file1"><br>
        Enter filename to upload: <input type="file" name="file2"><br>
        Enter filename to upload: <input type="file" name="file3"><br>
        <input type="submit">
        </form>
        </BODY>
        </HTML>
 

Script for 'sample2.asp':

     <%
        Set obj= Server.CreateObject("SoftArtisans.SAFile")
        obj.form("file1").save
        obj.form("file2").saveAs "MyHtml.html"
        obj.form("file3").saveInVirtual
        user1 = obj.form("file1").UserFileName
        user2 = obj.form("file2").UserFileName
        user3 = obj.form("file3").UserFileName

        Response.Write user1
        Response.Write user2
        Response.Write user3
        %>




Property Name: Count

This is a Read-Only property. Count returns the total number of components present on the Form.

Example:
(for retrieving count )

Script for 'sample2.asp':

     <%
        Set obj= Server.CreateObject("SoftArtisans.SAFile")
        count=obj.Count
        Response.Write count
       %>




Property Name:  MaxBytes

This is a Read/Write property. MaxBytes determines the maximum number of bytes of file which are to be transferred to the Server. If a file greater in size than MaxBytes is uploaded, then only MaxBytes are transferred.

Example:
(for setting maximum bytes )

Script for 'maxbytesSample.asp':

     <%
        Set obj= Server.CreateObject("SoftArtisans.SAFile")
        obj.MaxBytes =1024*1024    ' i.e. 1MB
        obj.form("file1").save    ' file greater than 1MB shall be truncated
        obj.MaxBytes =1024    ' i.e. 1KB
        obj.form("file2").saveAs "MyHtml.html"
        obj.MaxBytes =1024*4    ' i.e. 4KB
        obj.form("file3").saveInVirtual
        %>




Property Name: TotalBytes

This is a Read-Only property. TotalBytes determines the total number of bytes transferred to the Server.

Example:
(for getting total bytes )

Script for 'totalbytesSample.asp':

         <%
        Set obj = Server.CreateObject("SoftArtisans.SAFile")
        obj.form("file1").save
        total1=obj.TotalBytes
        obj.form("file2").saveAs "MyHtml.html"
        total2=obj.TotalBytes
        obj.form("file3").saveInVirtual
        total3=obj.TotalBytes

        Response.Write total1
        Response.Write total2
        Response.Write total3
        %>




Property Name:  OverWriteFiles

This is a Read/Write property. With the help of this property, the overwriting of any file can be controlled. By default, it set true i.e. any file having the name of an uploaded file shall be overwritten.

Example:
(for overwriting files)

Script for 'overwriteSample.asp':

         <%
        Set obj = Server.CreateObject("SoftArtisans.SAFile")
        ow=obj.OverWriteFiles
        if ow = true then
        obj.OverWriteFiles= false
        end if
        obj.form("file1").save    ' save but do not overwrite
        %>




Property Name:  IsEmpty

This is a Read-Only property. IsEmpty property shows whether the file uploaded contained data or not.

Example:
(for checking empty files)

Script for 'isemptySample.asp':

         <%
        Set obj = Server.CreateObject("SoftArtisans.SAFile")
        obj.form("file1").save
        empty=obj.form("file1").IsEmpty
        if empty = true then
        Response.Write "The file uploaded was empty"
        else
        Response.Write "The file uploaded contains data"
        end if
        %>




Property Name: Error

This is a Read-Only property. Error returns true or false depending upon whether the current task is successfully completed or not.

Example:
(for eveluating Error value)

Script for 'isemptySample.asp':

         <%
       Set obj = Server.CreateObject("SoftArtisans.SAFile")
        obj.form("file1").save
        err=obj.Error
        if err = true then
        Response.Write "The file is uploaded successfully"
        else
        Response.Write "Error in uploading the file"
        end if
        %>




Property Name:  form

This is the key method which returns the object of UploadDictionary which holds all the information about the form elements and the files. It not only works similar to ASP's Request.Form but it can be used to access the file properties and methods in case of multiple uploads.

Example:
(accessing fields of the 'form' for multiple files upload)

Html page:

         <HTML>  <HEAD>
        <TITLE>Multiple File Upload via SAFile</TITLE>
        </HEAD>
        <BODY>
        <form enctype="multipart/form-data" method="post" action="sample2.asp">
         Enter Path1:<input  name="f1"><br>
         Enter filename to upload: <input type="file" name="file1"><br>
         Enter Path2:<input  name="f2"><br>
         Enter filename to upload: <input type="file" name="file2"><br>
        <input type="submit">
        </form>
        </BODY>
        </HTML>

Script for 'sample2.asp':

         <HTML><HEAD>
        <TITLE>Accessing Form Fields </TITLE>
        </HEAD>
        <BODY>
        <%
        Set obj = Server.CreateObject("SoftArtisans.SAFile")
        path1 = obj.form("f1").Item    'and not obj.form("f1")
        obj.Path = path1
        obj.save
        obj.saveAs "MyHtml01.html"
        %>
        <BR>
        Thank you for uploading your file.
        </BODY>
        </HTML>

In the above example, the user enters the path name into the text field. The user can get this value by the obj.form(fieldname).Item method (and not by obj.form(fieldname) )  the browsed file can then be uploaded to the specified path by 'saveAs' method.




Property Name:  DateLastModified

This is a Read-Only property. DateLastModified determines the last modified date of the last uploaded file.  The date is displayed in the Local Time Zone.

It works if the client browser sends this information. ( Internet Explorer and Netscape Navigator do not send this infomation in the request ).

Example:
(getting DateLastModified for single file upload)

Html page:

         <HTML>  <HEAD>
        <TITLE>Multiple File Upload via SAFile</TITLE>
        </HEAD>
        <BODY>
        <form enctype="multipart/form-data" method="post" action="sample2.asp">
        Enter filename to upload: <input type="file" name="file1"><br>
        <input type="submit">
        </form>
        </BODY>
        </HTML>
 

Script for 'sample2.asp':

        <%
        Set obj = Server.CreateObject("SoftArtisans.SAFile")
        oj.form("file1").save
        dt = obj.DateLastModified
        Response.Write dt    'will return, say,  Sat May 29 11:40:42 GMT 1999
        %>




Property Name:  DateLastModifiedUTC

This is a Read-Only property. DateLastModifiedUTC determines the last modified date of the last uploaded file.  The date is displayed in the Universal Time (UTC or GMT).

It works if the client browser sends this information. ( Internet Explorer and Netscape Navigator do not send this infomation in the request ).

Example:
(getting DateLastModifiedUTC  for single file upload)

Html page:

         <HTML>  <HEAD>
        <TITLE>Multiple File Upload via SAFile</TITLE>
        </HEAD>
        <BODY>
        <form enctype="multipart/form-data" method="post" action="sample2.asp">
        Enter filename to upload: <input type="file" name="file1"><br>
        <input type="submit">
        </form>
        </BODY>
        </HTML>
 

Script for 'sample2.asp':

        <%
        Set obj = Server.CreateObject("SoftArtisans.SAFile")
        oj.form("file1").save
        dtUTC = obj.DateLastModifiedUTC
        Response.Write dtUTC    'will return, say,  Sat May 29 11:40:42 GMT 1999
        %>




Property Name:  UseDateLastModified

This is a Read/Write property. UseDateLastModified determines whether the last uploaded file will hold the last modified date of the user's original file on the Server or not. By default , this property is set false.

It works if the client browser sends this information. ( Internet Explorer and Netscape Navigator do not send this infomation in the request ).

Script for 'sample2.asp':

        <%
        Set obj = Server.CreateObject("SoftArtisans.SAFile")
        obj.UseDateLastModified= true
        oj.form("file1").save    'saved with user's original file date
        %>




Property Name:  MIMEVersion

This is a Read-Only property.  MIMEVer contains the MIME version of the file uploaded.

This property works if the client browser sends this information. ( Internet Explorer and Netscape Navigator do not send this infomation in the request ).

Example:
(for checking MIME Type of files)

Script for 'MimeVerSample.asp':

         <%
        Set obj = Server.CreateObject("SoftArtisans.SAFile")
        obj.form("file1").save
        obj.form("file2").save
        Response.Write obj.form("file1").MIMEVersion
        Response.Write obj.form("file2").MIMEVersion
       %>
 

 Back to SAFile      Back to Methods      Back to Properties     Back to iASP_FileUp