problem in write byte in a file using FileStream |
| Arvind Kumar posted at 03-Jul-08 05:26 |
|
private void m_ibtSearch_Click(object sender, ImageClickEventArgs e)
{
Byte[] response= null;
if (Directory.Exists(dirPath))
{
fPath=dirPath + "/Report" + reportName + ".pdf";
}
else
{
Directory.CreateDirectory(dirPath);
fPath=dirPath + "/Report" + reportName + ".pdf";
}
//Checking whether file already exists then delete old file.
if(File.Exists(fPath))
File.Delete(fPath);
for (int i=1 ; i<= rowCount;i=i+200)
{
if (i == 1)
{
objRptIP.PageNo =i;
// this method return byte of array
response = objRptIP.RenderReport();
FileStream fStream=File.OpenWrite(fPath);
fStream.Write(response,0,response.Length);
fStream.Close();
}
else
{
objRptIP.PageNo =i;
// byte[] response1 = null;
// byte[] response2 = null;
// response1 = objRptIP.RenderReport();
// response2 = this.AppendArrays(response, response1);
// FileStream fStream=File.OpenWrite(fPath);
// fStream.Write(response2,0,response2.Length);
// fStream.Close();
response = objRptIP.RenderReport();
// FileStream fStream=File.OpenWrite(fPath);
FileStream fStream=File.Open(fPath,FileMode.Append ,FileAccess.Write);
fStream.Seek(1 ,SeekOrigin.End);
fStream.Write(response,0 ,response.Length);
fStream.Close();
if(i > 200)
break;
}
}
I am try to write a pdf file in loop where each iteration i got some byte array but porblem is here first time write the byte of array to a pdf file and next iteration it did not write end of the file which is i need, it overwrite previous data in every iteration of loop where as i have check on phisical location every time increase the size of the pdf file but i try to open that pdf it shows only last iteration byte value. |
|