Home     Products      Support      Corporate     Sign In 
Support Knowledge Base, Article 897
Product
XFile
Version
all versions
Title
Using XFile in a ASP.NET web application with codebehind
Problem
XFile is not a .NET control and may require special planning when using it in a .NET application. The following article explains some of these considerations and provides a sample Visual Studio .NET project as a code sample.
Solution
Features of This Sample:

  • Uses XFile's Graphical User Interface (Visual Control)
  • Uses XFile's Progress Indicator
  • Is presented as a Visual Studio .NET project
  • Uses Code Behind
  • Uses FileUp to process the upload request.
  • Upload Request submits an additional form element for processing.

How this code sample is designed:

This code sample is set up so that all of XFile and FileUp related code exist in one of two branches of code in the Page_load event handler. The branches test if the Page_Load event was a PostBack. The first time the page loads, it will not be a PostBack. Here we will load the XFile related code. When XFile is used to post the upload request, this will be handled by the Page_Load event handler again, but this time, the IsPostBack property will return "true". The FileUp code is placed in this branch.

Private Sub Page_Load(ByVal sender As System.Object,
     ByVal e As System.EventArgs) Handles MyBase.Load

  If (Page.IsPostBack) = False Then

  (...all XFile and form related code.)

  End If

  If (Page.IsPostBack) Then

  (...all FileUp and Request processing code.)

  End If
End Sub

If the page has not posted back, then it is loading for the first time. Here XFile will be instantiated. All other controls on this page will have the AutoPostBack property set to "false" so that no events other then submitting the files for upload can trigger a PostBack event.

When the form is submitted, the page will reload as a PostBack. In this branch of code, FileUp is instantiated to process the upload request and save the files to disk. The Response sent back to the client will include information about the files uploaded, where they were saved and a link will be provided to re-instantiate XFile and submit new files for uploading if the user requires this.

Limiting Automatic Postbacks:

An automatic PostBack event would cause all of the files added to XFile's file collection to be submitted for uploading. The problems with this include:

  • The user may not be finished or ready to submit the files.
  • XFile requires a manual reset of its file transfer engine (the XFRequest object) once its files have been sent. It cannot submit files twice; it must be reset.
  • When XFile is manually reset, its file collection will be emptied. XFile cannot maintain a viewstate like a .NET control.
  • Even if a work-around were provided to mimick maintaining a viewstate for XFile(maintaining a list files in a hidden form element, manually resetting the control and adding the files back into the collection for each automatic postback event), the files would still be part of each trip to the server, which is a waste of bandwith.

If your XFile web application requires the use of server-side validation, it is recommended to break the XFile functionality off into a separate page. Allow your server-validating controls to function on one page, and then instantiate XFile on a separate page, so that you can prevent any PostBack events from occurring on the XFile page until you are ready to send the files to the server.

Notes about setting up the project on your webserver:

Two projects are provided for this sample. XFileDoNetSample.zip contains a project that does not use the FileUp HttpModule. XFileDotNetITKB.zip contains a project that uses the HttpModule. It is recommended that you use the HttpModule to overcome .NET performance limitations. For more information on these limitations, please see: http://fileup.softartisans.com/fileup-242.aspx

  1. XFileDotNetSample.zip: XFile and FileUp in .NET without the FileUp HttpModule
    • This is a Visual Studio .NET 2003 project.

    • Unpack this zip file to a directory on your webserver and map it to an application directory in IIS named "XFileDotNetSample".

    • It was compiled with a (required) reference to the safileup.dll file. This file is not included in the project. You must add a reference to your own safileup.dll. If you do not own a license to FileUp, an evaluation copy may be downloaded from our website at: http://support.softartisans.com/eval.aspx

    • The XFile is also required to run this project, but it does not need to be added as a reference. This project has been compiled as if the machine that functions as the webserver, will also be the machine at which you open the client browser. If XFile is installed on this machine, it can be found by the CLSID in the registry. If you using a second machine as a client, then the codebase attribute of XFile's object tag will need to be edited to point to the URL where the XFile CAB file can be downloaded from your webserver.

    • FileUp will try to save the files to a directory named "C:\Save Here". If this directory does not exist on your webserver, either change the path property in the code, or create this directory. Be certain to provide appropriate NTFS permissions to allow the web application to write to this directory. For more information on how this is done is ASP.NET, please see Setting Appropriate Security

    • Build the project after making these changes.



  2. XFileDotNetITKB.zip: XFile and FileUp in .NET using the FileUp HttpModule (recommended)
    • This is a Visual Studio .NET 2003 project.

    • Unpack this zip file to a directory on your webserver and map it to an application directory in IIS named "XFileDotNetITKB".

    • It was compiled with a (required) reference to the safileup.dll file. This file is not included in the project. You must add a reference to your own safileup.dll. If you do not own a license to FileUp, an evaluation copy may be downloaded from our website at: http://support.softartisans.com/eval.aspx

    • The XFile is also required to run this project, but it does not need to be added as a reference. This project has been compiled as if the machine that functions as the webserver, will also be the machine at which you open the client browser. If XFile is installed on this machine, it can be found by the CLSID in the registry. If you using a second machine as a client, then the codebase attribute of XFile's object tag will need to be edited to point to the URL where the XFile CAB file can be downloaded from your webserver.

    • FileUp will try to save the files to a directory named "C:\Save Here". If this directory does not exist on your webserver, either change the path property in the code, or create this directory. Be certain to provide appropriate NTFS permissions to allow the web application to write to this directory. For more information on how this is done is ASP.NET, please see Setting Appropriate Security

    • This project uses the FileUp HttpModule. The FileUpModule.dll file is not included in this project. You will need to copy your own FileUpModule.dll file to the bin directory of the application. It does not need to be added to the project as a reference. You do however, need to edit the web.config file to reference the exact version number of the dll. Open the web.config file included with this project and locate the tags illustrated below. Replace the "x" placeholder with the exact version number of the FileUpModule.dll file. You can determine the version number of the dll by right-clicking on the dll, choosing properties, and clicking on the "version" tab.

        <httpModules>
           <add name="FileUpModule"
            type="SoftArtisans.Net.FileUpModule,
            FileUpModule,
            Version=x.x.x.xxx,
            Culture=neutral,
            PublicKeyToken=f593502af6ee46ae"/>
        </httpModules>
        <httpHandlers>
           <add verb="*" path="*.uplx" type="System.Web.UI.PageHandlerFactory"/>
        </httpHandlers>

    • Build the project after making these changes.

Attachments
Attachments/KB897_XFileDotNetITKB.zip
Attachments/KB897_XFileDotNetSample.zip
Created : 6/23/2005 12:39:29 PM (last modified : 6/23/2005 12:39:29 PM)
Rate this article!
Comments