writing to the existing file.

N

nasirmajor

Dear all i have the following code for writing to the existing file.


===========================
void AppendToFileEng()
{
SqlDataReader gr = null;
string engpath2="";
gr = db.GetReader("Select * from tbl_SubCat2 Where
SId2=" + SId2 + "");
if (gr.Read())
{

engpath2 = gr[5].ToString();


}
string strfname = Server.MapPath(@"..\" + engpath2);

Response.Write(strfname);

StreamWriter fp = File.AppendText(strfname);
//what should be done here or else where

fp.WriteLine(txtengfile.Text);

fp.Close();
fp.Dispose();
}
==================================

well this file do write to the existing file but it does not edit the
file

e.g if the followig line is in the text file

------> this is wrong file

and if after i write to file this line and delete above line

------> this is ok file

then previous line also remains there and new line is added as well i.e
output comes like this

------> this is wrong file

------> this is ok file


i want the line "this is wrong file" to be removed and just "this is ok
file" line.

Thanks in advance.
 
N

nasirmajor

void AppendToFileEng()
{
SqlDataReader gr = null;
string engpath2 = "";
string arbpath2 = "";
gr = db.GetReader("Select * from tbl_SubCat2 Where SId2=" +
SId2 + "");
if (gr.Read())
{

engpath2 = gr[5].ToString();
arbpath2 = gr[6].ToString();

}
string strfnameeng = Server.MapPath(@"..\" + engpath2);
string strfnamearb = Server.MapPath(@"..\" + arbpath2);
File.Delete(strfnameeng);
File.Delete(strfnamearb);

StreamWriter fp = File.AppendText(strfnameeng);
StreamWriter fp2 = File.AppendText(strfnamearb);

fp.WriteLine(txtengfile.Text);
fp2.WriteLine(txtarabfile.Text);

fp.Close();
fp2.Close();


}


Regards Your self
 

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

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top