|
Double click on the submit button to bring up the codebehind
page.
You will need to add the ABCUpload namespace.
You will need to add code to register the progress bar when the
page is loaded and to save the file when the submit button is
clicked.
The sections you need to add are shown below in red.
Note that the UploadedFile.Detach method (detailed in the
Pure HTML Progress Bar Upload
Example) is often a more efficient method to use for saving
large uploaded files. The code here is designed for simplicity and
robustness rather than optimal performance.
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using
WebSupergoo.ABCUpload6;
public partial class myupload : System.Web.UI.Page
{
protected void Page_Load(object sender,
EventArgs e)
{
if
(!ClientScript.IsClientScriptBlockRegistered("DoUpload")) {
string
theScript = "\r\n";
theScript
+= "<script language=JavaScript>\r\n";
theScript
+= "<!--\r\n";
theScript
+= "function DoUpload(inForm) {\r\n";
theScript
+= " if ((typeof(Page_BlockSubmit) == 'boolean') &&
(Page_BlockSubmit == true)) return;\r\n";
theScript
+= " theFeats =
'height=160,width=600,location=no,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no';\r\n";
theScript
+= " theUniqueID = Math.floor(Math.random() * 1000000) * ((new
Date()).getTime() % 1000);\r\n";
theScript
+= " window.open('progressbar.aspx?ProgressID=' + theUniqueID,
theUniqueID, theFeats);\r\n";
theScript
+= " inForm = inForm.document.forms[0];\r\n";
theScript
+= " thePos = inForm.action.indexOf('?');\r\n";
theScript
+= " if (thePos >= 0)\r\n";
theScript
+= " inForm.action = inForm.action.substring(0, thePos);\r\n";
theScript
+= " inForm.action += '?UploadID=' + theUniqueID;\r\n";
theScript
+= " inForm.submit();\r\n";
theScript
+= "}\r\n";
theScript
+= "//-->\r\n";
theScript
+= "</script>\r\n";
ClientScript.RegisterClientScriptBlock(this.GetType(),
"DoUpload", theScript);
}
ClientScript.RegisterOnSubmitStatement(this.GetType(),
"submit", "DoUpload(this);");
}
protected void Button1_Click(object sender,
EventArgs e)
{
Upload theUpload = new Upload();
UploadedFile
theFile = theUpload.Files["myfile"];
if ((theFile !=
null) && (theFile.ContentLength > 0))
theFile.SaveAs(theFile.WinSafeFileName);
}
}
Imports
WebSupergoo.ABCUpload6
Partial Class WebForm1
Inherits System.Web.UI.Page
Private Sub
Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Me.Load
If
ClientScript.IsClientScriptBlockRegistered("DoUpload") = False
Then
Dim
sc As String = vbCrLf
sc
= sc + "<script language=JavaScript>" + vbCrLf
sc
= sc + "<!--" + vbCrLf
sc
= sc + "function DoUpload(inForm) {" + vbCrLf
sc
= sc + " if ((typeof(Page_BlockSubmit) == 'boolean') &&
(Page_BlockSubmit == true)) return;" + vbCrLf
sc
= sc + " theFeats =
'height=160,width=600,location=no,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no';"
+ vbCrLf
sc
= sc + " theUniqueID = Math.floor(Math.random() * 1000000) * ((new
Date()).getTime() % 1000);" + vbCrLf
sc
= sc + " window.open('progressbar.aspx?ProgressID=' + theUniqueID,
theUniqueID, theFeats);" + vbCrLf
sc
= sc + " inForm = inForm.document.forms[0];" + vbCrLf
sc
= sc + " thePos = inForm.action.indexOf('?');" + vbCrLf
sc
= sc + " if (thePos >= 0)" + vbCrLf
sc
= sc + " inForm.action = inForm.action.substring(0, thePos);" +
vbCrLf
sc
= sc + " inForm.action += '?UploadID=' + theUniqueID;" + vbCrLf
sc
= sc + " inForm.submit();" + vbCrLf
sc
= sc + "}" + vbCrLf
sc
= sc + "//-->" + vbCrLf
sc
= sc + "</script>" + vbCrLf
ClientScript.RegisterClientScriptBlock(Me.GetType(),
"DoUpload", sc)
End If
ClientScript.RegisterOnSubmitStatement(Me.GetType(),
"submit", "DoUpload(this);")
End Sub
Protected Sub Button1_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
Dim theUpload As Upload = new Upload()
Dim theFile As
UploadedFile = theUpload.Files("myfile")
If Not theFile Is
Nothing And theFile.ContentLength > 0 Then
theFile.SaveAs(theFile.WinSafeFileName)
End
If
End Sub
End Class
|
|
|