各位编程高手,我是学习C#的学生,现有一个问题想请教大家,如何把在richTextBox控件中显示的内容按照系统当时的年月日小时分钟保存命名呢呢?现在保存后txt文件名字为Save As cuiyang0729.txt,我希望命名格式为2012-02-22-10-20.txt,明天保存则自动为2012-02-23-13-15.txt,谢谢大家啦~~~
源代码如下:
private void button5_Click(object sender, EventArgs e)
{
string spath = "F:\\Save As cuiyang0729.txt"; //保存的路径
string s = richTextBox2.Text.Trim().ToString();
string s1 = s;
FileStream stream = File.OpenWrite(spath);
byte[] by = Encoding.UTF8.GetBytes(s);
BinaryWriter writer = new BinaryWriter(stream);//写入文件
writer.Write(by, 0, by.Length);
writer.Close();
stream.Close();
}
源代码如下:
private void button5_Click(object sender, EventArgs e)
{
string spath = "F:\\Save As cuiyang0729.txt"; //保存的路径
string s = richTextBox2.Text.Trim().ToString();
string s1 = s;
FileStream stream = File.OpenWrite(spath);
byte[] by = Encoding.UTF8.GetBytes(s);
BinaryWriter writer = new BinaryWriter(stream);//写入文件
writer.Write(by, 0, by.Length);
writer.Close();
stream.Close();
}
解决方案 »
- BMP文件可以查看,但是用函数调用提示文件无效,使用画图工具另存之后有效
- 求助:在做MDI窗体工具栏时出现“未将对象引用设置到对象的实例”提示,该如何解决?
- C#中如何统计字符串中相匹配的字符串的个数,例如:qweqwrerteeeety中qw的个数有两个
- 在C#中 如何将 UTF-8 编码转换成 ANSI 编码
- 用户对象的枚举属性
- 求面试过yahoo中国的同志指点
- C#中如何实现扫描一个文件夹下所有文件并将文件名和相应的绝对路径记录入数据库?
- System.Timer事件触发
- .net 控制台程序运行一段时间后老飞,什么原因,有图,求高手解决
- 大小屏效果同步
- WebBrowser.Document.Body.OuerHtml 乱码
- C# 调用C++做的WEN服务
换成
string spath = "F:\\"+DateTime.Now.ToString("yyyy-MM-dd hh:mm")+".txt"; //保存的路径
可是在编译时,这一行FileStream stream = File.OpenWrite(spath);
出现“不支持给定路径的格式”,是为什么呢?
可是在编译时,这一行FileStream stream = File.OpenWrite(spath);
出现“不支持给定路径的格式”,是为什么呢?
string spath = "F:\\" + DateTime.Now.ToString("yyyy-MM-dd hh-mm") + ".txt";
可是在编译时,这一行FileStream stream = File.OpenWrite(spath);
出现“不支持给定路径的格式”,是为什么呢?
你把 hh:mm 中的 : 替换成其它的字符,吧