473,395 Members | 1,931 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Question about HttpModule for file upload progress bar

Hi guys,

I am trying to write a httpmodule to implement upload file progress bar.
I searched web and got some sample code from code project
(http://www.codeproject.com/aspnet/Fi...56#xx1079964xx)
Here is the code I modified. The problem is: if I don't use guid in this
function, it works fine. but if I get guid from querystring or form
field, the file will not be uploaded and the while loop never execute in
this function. Please help. Thanks!

private void context_BeginRequest(object sender, EventArgs e)
{
HttpApplication httpApp = (HttpApplication)sender;
//string guid2 = httpApp.Context.Request.Params["guid"]; (--If I
uncomment this line and comment next line it won't work.)
string guid2 = "";
uploadKey = guid2+"uploadprogress";
contentLengthKey = guid2+"uploadlength";

if (httpApp.Context.Request.Path.IndexOf("/WebForm1.aspx") > 0)
{
HttpWorkerRequest worker = GetWorkerRequest(httpApp.Context);
rwl = new ReaderWriterLock();
buffer = 1024;

if (httpApp.Context.Request.ContentLength > 0)
{
TotalSize = httpApp.Context.Request.ContentLength;
System.IO.MemoryStream stream = new System.IO.MemoryStream();
byte[] data = worker.GetPreloadedEntityBody();
stream.Write(data,0,data.Length);

int read = 0;
int counter = data.Length;

while(counter < httpApp.Context.Request.ContentLength)
{
if ((counter + buffer) > httpApp.Context.Request.ContentLength )
buffer = httpApp.Context.Request.ContentLength - counter;
data = new byte[buffer];
UploadSize = counter;
read = worker.ReadEntityBody(data,buffer);
if (read == 0)
return;

counter += read;

stream.Write(data,0,buffer);
httpApp.Context.Response.Write("Counter: " + counter.ToString() +
"<br>");
}
stream.Seek(0,0);
byte[] allData = new byte[(int)stream.Length];
stream.Read(allData,0,allData.Length);
PushRequestToIIS(worker,allData);
}
}
}
Nov 19 '05 #1
1 5648
I fount the problem. Since the upload file form are multipart/form-data
enctype, I can't use Request.Params to access the form fields.

So another question is How can I access the those fields in the
enctype="multipart/form-data" form? Thanks!

Li

Li Zhang wrote:
Hi guys,

I am trying to write a httpmodule to implement upload file progress bar.
I searched web and got some sample code from code project
(http://www.codeproject.com/aspnet/Fi...56#xx1079964xx)

Here is the code I modified. The problem is: if I don't use guid in this
function, it works fine. but if I get guid from querystring or form
field, the file will not be uploaded and the while loop never execute in
this function. Please help. Thanks!

private void context_BeginRequest(object sender, EventArgs e)
{
HttpApplication httpApp = (HttpApplication)sender;
//string guid2 = httpApp.Context.Request.Params["guid"];
(--If I uncomment this line and comment next line it won't work.)
string guid2 = "";
uploadKey = guid2+"uploadprogress";
contentLengthKey = guid2+"uploadlength";

if (httpApp.Context.Request.Path.IndexOf("/WebForm1.aspx") > 0)
{
HttpWorkerRequest worker =
GetWorkerRequest(httpApp.Context);
rwl = new ReaderWriterLock();
buffer = 1024;

if (httpApp.Context.Request.ContentLength > 0)
{
TotalSize = httpApp.Context.Request.ContentLength;
System.IO.MemoryStream stream = new
System.IO.MemoryStream();
byte[] data = worker.GetPreloadedEntityBody();
stream.Write(data,0,data.Length);

int read = 0;
int counter = data.Length;

while(counter < httpApp.Context.Request.ContentLength)
{
if ((counter + buffer) >
httpApp.Context.Request.ContentLength )
buffer =
httpApp.Context.Request.ContentLength - counter;
data = new byte[buffer];
UploadSize = counter;
read = worker.ReadEntityBody(data,buffer);
if (read == 0)
return;

counter += read;

stream.Write(data,0,buffer);
httpApp.Context.Response.Write("Counter: " +
counter.ToString() + "<br>");
}
stream.Seek(0,0);
byte[] allData = new byte[(int)stream.Length];
stream.Read(allData,0,allData.Length);
PushRequestToIIS(worker,allData);
}
}
}

Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Todd Denlinger | last post by:
Ok, I know how to upload a file in asp.net using the <input type="file" runat="server"> control. What I don't know how to do is monitor the progress of the upload so that I can show the...
3
by: parthivjoshi | last post by:
Do anyone have the idea how to add progressbar to the existing HTTPModule and HTTPApplication for File Upload. ********************************************************************** Sent via...
12
by: JMB | last post by:
Hello, I was wondering if anyone knew of any projects extending the inline upload progress bar to utilize an inpage image uploader with bar, without having to refresh or go to a seperate page,...
4
by: Pavils Jurjans | last post by:
Hello, I have the following setup: The page that contains the form with file upolad HTML control resides on another server that doesn't have ASP.NET available. It may well be just static...
6
by: Marko Vuksanovic | last post by:
I am trying to implement a file upload progress indicator (doesn't have to be a progress bar) using atlas... I do realize that the indicator cannot be implemented using Update panel control, but is...
1
by: Marko Vuksanovic | last post by:
I used the following code for implementing a file upload progress indicator, using UpdateProgress Panel, though I have a problem that FileUpload.Has File always returns false. Any suggestions what...
5
by: LtCommander | last post by:
Hello all, 1. I am a little new to ASP.NET, so please bear with me. 2. I am trying to create a very simple website which requires an upload box (end user file sizes may be anywhere between 1MB...
0
by: Andy | last post by:
Hi folks, I wrote a HttpModule to handle file uploads (on beginRequest) prior to the actual web form displaying the result. The file upload processing generally works very well also for large...
3
by: shapper | last post by:
Hello, I need to upload a file. Can I only do this with the File Upload control? I also need the following: - Send upload info, upload percentage, continuously to a JavaScript function so...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.