且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

保存具有相同名称的文件

更新时间:2023-02-25 15:26:57

没有SaveDat.SaveDatArr方法代码,我们无法告诉你你做错了什么 - 因为我们看不到你是什么干嘛!



但是...猜测你要么使用File.AppendText要么打开一个流来追加而不是覆盖:

 ... =  new  StreamWriter( @  D:\Temp \Data_Entry.dat true ); 

要么改变 true false ,或使用单参数版本:

 ... =  new  StreamWriter( @  d:\Temp\Data_Entry.dat跨度>); 


Hi All,

I'm reading a file (Filename: Data_Entry.dat) into gridview and modifying the data. After modification, if i save the file with different name then there is no issues.

If i save the file after modifications with same name (Data_Entry.dat), then the modification is existing but the records in the file are getting double. (If file contains 10 records, after saving with same name it's giving 20records).
Below is the code i programmed under save button:


===========Code===================

ClsSaveDat Savdat = new ClsSaveDat();
Savdat.SaveDatArr(datfile);

==================================

Please let me know if i'm unclear about my query or anything. Thanks in advance.

Without the SaveDat.SaveDatArr method code, we can't tell you what you are doing wrong - because we can't see what you are doing at all!

But...At a guess you are either using File.AppendText or opening a stream for append instead of overwrite:
... = new StreamWriter(@"D:\Temp\Data_Entry.dat", true);

Either change the true to false, or use the single parameter version:

... = new StreamWriter(@"D:\Temp\Data_Entry.dat");