保存具有相同名称的文件 [英] Saving a file with same name

查看:101
本文介绍了保存具有相同名称的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我正在将文件(文件名:Data_Entry.dat)读入gridview并修改数据。修改后,如果我使用不同的名称保存文件,则没有问题。



如果我在修改后使用相同名称(Data_Entry.dat)保存文件,则修改已存在,但文件中的记录增加了一倍。 (如果文件包含10条记录,则在使用相同名称保存后,它将提供20条记录)。

以下是我在保存按钮下编程的代码:





======== ===代码===================



ClsSaveDat Savdat = new ClsSaveDat();

Savdat.SaveDatArr(datfile);



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



如果我不清楚我的查询或任何事情,请告诉我。在此先感谢。

解决方案

没有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");


这篇关于保存具有相同名称的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆