PC Review


Reply
Thread Tools Rate Thread

Ajax Update Progress control

 
 
Mike P
Guest
Posts: n/a
 
      24th May 2007
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.



*** Sent via Developersdex http://www.developersdex.com ***
 
Reply With Quote
 
 
 
 
bruce barker
Guest
Posts: n/a
 
      24th May 2007
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 P wrote:
> 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.
>
>
>
> *** Sent via Developersdex http://www.developersdex.com ***

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
AJAX and progress Matt Microsoft ASP .NET 4 5th Mar 2009 11:43 AM
Update Incremental Progress using AJAX TD is PSP Microsoft C# .NET 0 6th Oct 2008 06:03 AM
Problem with update Panel ajax control. chandan kumar Microsoft C# .NET 0 30th Sep 2008 07:46 AM
ASP.NET AJAX samples... I am looking for help with HoverMenu AJAX Toolbox control. JDeats Microsoft ASP .NET 1 5th Oct 2007 08:50 PM
Dropping a control on a webform and AJAX Update panel resize question William LaMartin Microsoft ASP .NET 0 24th May 2007 03:43 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:03 AM.