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.
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.