UploadBarDotNet tool |
|
This section will guide you through the steps required to incorporate UploadBarDotNet into a web site. PrerequisitesMicrosoft IIS Microsoft .NET framework UploadBarDotNet installed from the supplied MSI installer A valid license key obtained from Leading IT Note on uploading large filesFor security purposes, the maximum upload limit
for a machine is capped using a value in the machine.config file for
the local .NET
framework. The tag To increase the absolute limit for the machine,
edit machine.config, found in {Windows
directory}\Microsoft.NET\Framework\{.NET
version}\CONFIG\machine.config, and update the For example, to limit the machine
file upload size to 10 megabytes, edit the file
"C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\config\machine.config"
and set the
Integration steps
|
Once installed, the DLL will be found in the bin directory under the installation path. To use the DLL, it must be placed under the bin directory of the web site in which it is to be used. The namespace of the DLL is LIT.UploadBar. Each web site which uses the DLL must specify the
configuration data via the web.config file
for that web site. The following lines need to be included in that
document under the configuration tag. Note
that the <configsections> <sectiongroup name="lit.uploadbar"> <section name="core" type="System.Configuration.SingleTagSectionHandler, System, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> <section name="optional" type="System.Configuration.SingleTagSectionHandler, System, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> <section name="registrationCodes" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/> </sectiongroup> </configsections> <!-- The uploader config data --> <lit.uploadbar> <core uploadidqueryfield="UploadID" /> <optional chunksize="8192" samplesize="32768" statuslifehours="24" safefilenames="True"> </optional> <registrationcodes> </registrationcodes> </lit.uploadbar> Parameters
<system.web>
: <httpmodules> <add name="UploadHelper" type="LIT.UploadBar.UploadHelper, UploadBar" /> </httpmodules> |
Once the web.config has been set up correctly, the
central class will automatically monitor any uploads made to pages
containing the query field defined by the key uploadidqueryfield
in the This package has two classes within in which expose methods for the acquisition, control, and formatting of data associated with uploads. These classes are described in the support classes section. Support ClassesUploadDetails classThis class handles the details for all uploads within the web site. It exposes two methods: GetStatus methodpublic static bool GetStatus(string uniqueId, out string sourceFileName, out int bytesRead, out int bytesTotal, out int percentage, out bool completed, out string[] fileList, out int timeToCompletion, out double dataRate) Parameters
ClearProgress methodpublic static void ClearProgress(string uniqueId) Parameters
UploadHelperUtils classThis class contains methods for the formatting of data prior to display. It exposes two methods: FormatBytes methodpublic static string FormatBytes(long inputBytes) Parameters
Return values
BuildProgressBar methodpublic static HtmlTable BuildProgressBar(int percentage, string emptyClass, string filledClass, string tableClass) Parameters
Return values
|
Each upload requires an ID in order to distinguish between simultaneous uploads running on the system. This ID needs to be generated before the upload starts, and must be passed both to the page generating the upload, and the upload progress bar. This is performed via the query string. The name of the variable in the query string is defined in the web.config, under the key uploadidqueryfield, as describer earlier in this document. The following segment of code shows the
registration of a block of javascript against the // Generate a GUID for any uploads to be performed. string uploadGUID = HttpUtility.UrlEncode(Guid.NewGuid().ToString()); // Build up the client side script (javascript) string script = ""; script += "<script type=\"text/javascript\"><!--\r\n"; script += "function StartUpload()\r\n"; script += "{\r\n"; // The progress bar window opener script += "window.open('UploadProgressBar.aspx?UploadID=" + uploadGUID + "', 'UploadProgressBar', 'width=500, height=140, left=150, top=100, location=no, menubar=no, status=no, resizable=no, titlebar=no, toolbar=no, scrollbars=no');\r\n"; // The self reload code script += "document.Form1.action = 'Upload.aspx?UploadID=" + uploadGUID + "';"; script += "document.Form1.submit();\r\n"; script += "}\r\n"; script += "// -->\r\n"; script += "</script>\r\n"; // Place the script into the page RegisterClientScriptBlock("uploadStart", script); // Set the onclick event for the submit button // to execute the above script btnUpload.Attributes.Add("onclick", "StartUpload();"); |
Upon loading, a progress bar page must obtain the details for the batch which
it is monitoring.
The following sample shows how the data can be extracted from the
UploadDetails
class.
private void Page_Load(object sender, System.EventArgs e) { // Obtain the unique ID from the query string. string uniqueId; if (Request.QueryString["UploadID"] != null) uniqueId = Request.QueryString["UploadID"]; else return; // Variables which will be used to read/display the results string sourceFileName; int percentage, bytesRead, bytesTotal, timeToCompletion; double dataRate; bool completed; string[] fileNames; // Obtain the status for this upload UploadDetails.GetStatus(uniqueId, out sourceFileName, out bytesRead, out bytesTotal, out percentage, out completed, out fileNames, out timeRemaining, out dataRate); /***************** Continue page load code here *****************/ } |
Three sample projects are included in the 'sample' directory under the installation path. These contain commented sample web sites which demonstrate use of the upload control. To use these samples, simply mount the samples on the local web server, each in their own directory under UploadBarDotNetDemos, using the same name as the zip, e.g. Demo1.zip should be mounted at http://localhost/UploadBarDotNetDemos/Demo1. Simple upload - Demo1A very basic single file upload page offering a single popup window containing details about the current upload. Upload bar - Demo2An upload page containing a popup progress bar which displays a formatted html progress bar. It also demonstrates the multiple file upload capabilities of UploadBarDotNet. Inline upload bar - Demo3Displays upload information inside the same page as the submission page, using a combination of stylesheets and client side code to display the progress bar information. It also displays a progress list of the files received from the current upload. Only appropriate for multiple file uploads. Inline upload bar with background update - Demo4A special upload bar page for use over slow links. Instead of directly displaying a progress bar iframe, it communicates with a progress information page which updates the contents in the main page. This eliminates the 'flicker' experienced as the progress bar page reloads. Like the previous inline demo, this page displays a list of files received during the upload. |