Path Property

Object: SoftArtisans.FileUp
Syntax: Path[=Physical Path As String]
Type: String
Read/Write: Read/Write
Description:

This property defines the default directory for saving files. It also defines the default directory for caching files before a final save is executed in ASP, provided the property is set before any form elements or files are referenced in the script.

Note: In ASP.NET, when the FileUp HttpModule is implemented, the path property does not determine the caching location. Instead, the caching location must be set for the HttpModule, not the FileUp object. The path property, however, does still determine the default save location. (See: FileUp registry keys)

After determining the directory that will be used by the Path propery, you must also be certain to grant "read", "write" and "modify" NTFS permissions so that FileUp can cache or save to this location.

Setting the path property in ASP can improve performance in the following ways:

  • In ASP, the path property is checked to provide a location for caching. If a value is not provided, FileUp is forced to check other locations for a suitable directory.
  • When the FileUp object is responsible for caching (in ASP), if the path is not provided, it will attempt to cache to the location specified in your system TEMP variable, which is typically a location on the C: drive. In a typical webserver configuration, uploaded content will be saved to the D: drive or other volume. Moving the file across drives requires more system resources than moving the file to a different directory on the same drive.

In ASP, when the first upload reaches the server, FileUp will search for a writable Temp directory, and assign it to the Path property. FileUp will check the following: the TEMP environment variable, C:\Windows\Temp, C:\Winnt\Temp, C:\Temp, C:\tmp, and GetTempDir().

If FileUp does not find a writable Temp directory, and the Path property is not set in script, an error will occur. A Path assignment in script will overwrite FileUp's default Path value.

If you set Path, you can still save the file to a different location. When using the SaveAs method, specify a new complete path and file name. In this scenario, the upload is cached in the default path. When the SaveAs method is executed, the file is moved from the default path to the new destination. This works even if the new destination is on a different disk or on a network share.

Note: To change the system's default directory for cached files (the first directory FileUp will try to use as a default cache), reset the TEMP environment variable, as follows:
  • Open the Control Panel.
  • Select System.
  • Select the Advanced tab.
  • Click Environment variables...
  • Select TEMP from the System Variables list.
  • Click Edit.
  • Enter a new Variable Value, and click Ok.
Examples:

Cache and save the upload on the web server at C:\Uploads:

ASP <%
'--- Instantiate FileUp
Set fileUpload = Server.CreateObject("SoftArtisans.FileUp")

'--- Set cache/default save location to web server path
fileUpload.Path = "C:\Uploads"

'--- Save upload
fileUpload.Save
%>
C# //--- Instantiate FileUp
FileUp fileUpload = new FileUp(Context);

//--- Set default save location to web server path
//--- (Cache location is set using FileUpTempDir registry key) fileUpload.Path = @"C:\Uploads";

//--- Save upload
fileUpload.Save();
VB.NET '--- Instantiate FileUp
Dim fileUpload As New FileUp(Context);

'--- Set default save location to web server path
'--- (Cache location is set using FileUpTempDir registry key) fileUpload.Path = "C:\Uploads"

'--- Save upload
fileUpload.Save()

Cache and save the upload to a network shared drive:

ASP <%
'--- Instantiate FileUp
Set fileUpload = Server.CreateObject("SoftArtisans.FileUp")

'--- Set cache/default save location to network share
fileUpload.Path = "\\FileServer\Uploads"

'--- Save upload
fileUpload.Save
%>
C# //--- Instantiate FileUp
FileUp fileUpload = new FileUp(Context);

//--- Set default save location to network share
//--- (Cache location is set using FileUpTempDir registry key)
fileUpload.Path = @"\\FileServer\Uploads";

//--- Save upload
fileUpload.Save();
VB.NET '--- Instantiate FileUp
Dim fileUpload As New FileUp(Context);

'--- Set default save location to network share
'--- (Cache location is set using FileUpTempDir registry key)
fileUpload.Path = "\\FileServer\Uploads"

'--- Save upload
fileUpload.Save()

Cache the upload to the web server and save it to a network shared drive:

ASP <%
'--- Instantiate FileUp
Set fileUpload = Server.CreateObject("SoftArtisans.FileUp")

'--- Set cache/default save location to web server path
fileUpload.Path = "C:\Temp"

'--- Save upload to network share using original filename
fileUpload.SaveAs "\\FileServer\Uploads\" & _
fileUpload.form("File1").ShortFileName
%>
C# //--- Instantiate FileUp
FileUp fileUpload = new FileUp(Context);

//--- (Cache location is set to C:\Temp using FileUpTempDir
//--- registry key)

//--- Save upload to network share using original filename
fileUpload.SaveAs(@"\\FileServer\Uploads\" +
fileUpload.form("File1").ShortFileName);
VB.NET '--- Instantiate FileUp
Dim fileUpload As New FileUp(Context);

'--- (Cache location is set to C:\Temp using FileUpTempDir
'--- registry key)

'--- Save upload to network share using original filename
fileUpload.SaveAs("\\FileServer\Uploads\" + _
fileUpload.form("File1").ShortFileName)

Copyright © 2010 SoftArtisans, Inc. All rights reserved.