Question about HttpModule for file upload progress bar

L

Li Zhang

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/File_Upload_Progress_Bar.asp?df=100&forumid=155656#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);
}
}
}
 
L

Li Zhang

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top