如何创建文本文件.文件名应与上次创建的文件名不同. [英] How to create text file.The filen name should be diffent then last created file.

查看:99
本文介绍了如何创建文本文件.文件名应与上次创建的文件名不同.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何编码来创建带有不同id的文本文件,每当我单击按钮时,它将创建一个具有aa名称的文本文件,但文件名与上次创建的文件不同.之后,我将写一些东西并保存

How to codeing to create text file with different id on button click.Whenever i click on button it will create a text file with a a name but file name is different then last created file.After that i will write somthing and save it and also retrive data on web page.

推荐答案

1)您可以使用Guid作为文件名.

2)您可以保留一个计数器,并为每个保存的文件增加计数器.
1) You can use Guid as your file name.

2) You can keep a counter and increment that for each file saved.


尝试一下
string FileName=Test+DateTime.Now.ToString().Replace("/", "").Replace(".", "").Replace(":", "").Replace(" ", "")+".txt";
string text = "Test string to write inside the text file";
System.IO.File.WriteAllText(@FileName, text);


使用FileName + HH:MM:SS
连接文件 fileName024658

试试这个
Concatenate file with FileName + HH:MM:SS
fileName024658

Try this
string path = @"D:\";
string fileName = "TestFile" + DateTime.Now.ToString().Replace("/", "").Replace(":", "").Replace(" ", "") + ".txt";
File.Create(path + fileName);


这篇关于如何创建文本文件.文件名应与上次创建的文件名不同.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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