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.


Click here to sign in and reply. You could earn money via our $500 contest just for being helpful.
  problem in write byte in a file using FileStream - Arvind Kumar  03-Jul-08 05:26 5:26:30 AM
      try this... - Vasanthakumar D  03-Jul-08 05:50 5:50:21 AM
          this not help me - Arvind Kumar  03-Jul-08 05:53 5:53:35 AM
              no need to seek... - Vasanthakumar D  03-Jul-08 06:03 6:03:16 AM
                  it is not working - Arvind Kumar  03-Jul-08 06:14 6:14:56 AM
                      try this... - Vasanthakumar D  03-Jul-08 06:18 6:18:53 AM
                          sorry Vasanthakumar this si also not working - Arvind Kumar  04-Jul-08 02:18 2:18:20 AM
      Check this out - santhosh kumar  03-Jul-08 05:59 5:59:15 AM
View Posts