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);
}
}
}
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);
}
}
}