Ajax Update Progress control


M

Mike P

I am trying to apply the Update Progress control to a method that is
building a zip file and then giving the user the chance to save the file
via a popup box. But the Update Progress control doesn't seem to like
this. I am getting the error :

'Sys.WebForms.PageRequestManagerParserErrorException. The message
received from the server could not be parsed. Common causes for this
error are when the response is modified by calls to Response.Write(),
response filter, Http Modules, or server trace is enabled'

Here is my code :



private void BuildZip(string ZipName)

{

//try

//{

string strZipFullPath =
(string)ConfigurationManager.AppSettings["ZipCreateLocation"].ToString()
+ "\\" + ZipName.ToString();

// 'using' statements gaurantee the stream is closed properly which is a
big source

// of problems otherwise. Its exception safe as well which is great.

using (ZipOutputStream s = new
ZipOutputStream(File.Create(strZipFullPath)))

{

s.SetLevel(9); // 0 - store only to 9 - means best compression

byte[] buffer = new byte[4096];

foreach (GridViewRow gvr in Results.Rows)

{

CheckBox chkBox = (CheckBox)gvr.FindControl("RowLevelCheckBox");

if (chkBox.Checked == true)

{

string strFilename = gvr.Cells[0].Text.ToString();

string strFullPath = Session["Location"] + "\\" + strFilename;

ZipEntry entry = new ZipEntry(Path.GetFileName(strFullPath));

entry.DateTime = DateTime.Now;

s.PutNextEntry(entry);

using (FileStream fs = File.OpenRead(strFullPath))

{

// Using a fixed size buffer here makes no noticeable difference for
output

// but keeps a lid on memory usage.

int sourceBytes;

do

{

sourceBytes = fs.Read(buffer, 0, buffer.Length);

s.Write(buffer, 0, sourceBytes);

}

while (sourceBytes > 0);

}

}

}

// Finish/Close arent needed strictly as the using statement does this
automatically

// Finish is important to ensure trailing information for a Zip file is
appended. Without this

// the created file would be invalid.

s.Finish();

// Close is important to wrap things up and unlock the file.

s.Close();

FileStream fs1 = File.Open(strZipFullPath, FileMode.Open);

byte[] newbyte = new byte[fs1.Length];

fs1.Read(newbyte, 0, Convert.ToInt32(fs1.Length));

fs1.Close();

//delete file created on web server

File.Delete(strZipFullPath);

Response.AddHeader("Content-Disposition", "attachment; filename=" +
strZipFullPath);

//Response.OutputStream = "application/octect-stream";

Response.BinaryWrite(newbyte);

Response.End();

}

Any assistance would be really appreciated.
 
Ad

Advertisements

B

bruce barker

the update panel and progress control can not be used with this
scenario. they postback to the page and expect a specially formated xml
response that they parse, thus your message.

also as xmlhttprequest is used to do the fetch, there would be no way
for the user to save the file (say you placed it in a form field) as
javascript does not have permission to write a file.

to do this you need to use a link to download to a new target window,
then using ajax poll the server to see if the download is done (be sure
session is off on the download page or you will not be able to poll
during the download).


-- bruce (sqlwork.com)

Mike said:
I am trying to apply the Update Progress control to a method that is
building a zip file and then giving the user the chance to save the file
via a popup box. But the Update Progress control doesn't seem to like
this. I am getting the error :

'Sys.WebForms.PageRequestManagerParserErrorException. The message
received from the server could not be parsed. Common causes for this
error are when the response is modified by calls to Response.Write(),
response filter, Http Modules, or server trace is enabled'

Here is my code :



private void BuildZip(string ZipName)

{

//try

//{

string strZipFullPath =
(string)ConfigurationManager.AppSettings["ZipCreateLocation"].ToString()
+ "\\" + ZipName.ToString();

// 'using' statements gaurantee the stream is closed properly which is a
big source

// of problems otherwise. Its exception safe as well which is great.

using (ZipOutputStream s = new
ZipOutputStream(File.Create(strZipFullPath)))

{

s.SetLevel(9); // 0 - store only to 9 - means best compression

byte[] buffer = new byte[4096];

foreach (GridViewRow gvr in Results.Rows)

{

CheckBox chkBox = (CheckBox)gvr.FindControl("RowLevelCheckBox");

if (chkBox.Checked == true)

{

string strFilename = gvr.Cells[0].Text.ToString();

string strFullPath = Session["Location"] + "\\" + strFilename;

ZipEntry entry = new ZipEntry(Path.GetFileName(strFullPath));

entry.DateTime = DateTime.Now;

s.PutNextEntry(entry);

using (FileStream fs = File.OpenRead(strFullPath))

{

// Using a fixed size buffer here makes no noticeable difference for
output

// but keeps a lid on memory usage.

int sourceBytes;

do

{

sourceBytes = fs.Read(buffer, 0, buffer.Length);

s.Write(buffer, 0, sourceBytes);

}

while (sourceBytes > 0);

}

}

}

// Finish/Close arent needed strictly as the using statement does this
automatically

// Finish is important to ensure trailing information for a Zip file is
appended. Without this

// the created file would be invalid.

s.Finish();

// Close is important to wrap things up and unlock the file.

s.Close();

FileStream fs1 = File.Open(strZipFullPath, FileMode.Open);

byte[] newbyte = new byte[fs1.Length];

fs1.Read(newbyte, 0, Convert.ToInt32(fs1.Length));

fs1.Close();

//delete file created on web server

File.Delete(strZipFullPath);

Response.AddHeader("Content-Disposition", "attachment; filename=" +
strZipFullPath);

//Response.OutputStream = "application/octect-stream";

Response.BinaryWrite(newbyte);

Response.End();

}

Any assistance would be really appreciated.
 

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

Top