送分了,各位高人们,小弟初学者,想请各位帮个小忙!!!

lulude_1 2012-07-25 11:55:45
求代码!!!

怎样把textbox中的数据保存到D:\路径下为txt格式的文本中。
同时注意检查每个txt中信息的最大个数为10000条,如果大于10000,则写入一个新的文件,命名当天日期+N(1=<N)
...全文
116 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
lulude_1 2012-07-26
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 的回复:]

还是说一个文件只能保存一万个textbox里的字符串?
[/Quote]

是啊,多于一万条的重新创建新的文件
Anod 2012-07-25
  • 打赏
  • 举报
回复
textbox?

string yourfilepath="你要存储的文件路径";
StreamReader reader = new StreamReader(yourfilepath);
StreamWriter writer;
int count = 0;
// string[] aa=new string[]{System.Environment.NewLine};
count = reader.ReadToEnd().Split(new string[] { System.Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries).Length;
//或 while(reader .ReadLine())count++;
reader.Close();
if (count > 10000)
{
int index = yourfilepath.LastIndexOf("+");
int n ;
int.TryParse(index == -1 ? "0" : (yourfilepath.Substring(index == -1 ? 0 : index + 1)),out n);//序号
int indextemp = yourfilepath.Substring(0, index == -1 ? 0 : index).LastIndexOf("+");
string temp = yourfilepath.Substring(0, indextemp == -1 ? (yourfilepath.Length - 1) : indextemp);
string newfilepath = (n == 0 ? string.Empty : temp) + DateTime.Today.ToLongDateString() + "+" + (n + 1).ToString();
writer = new StreamWriter(newfilepath);
}
else writer = new StreamWriter(yourfilepath);
writer.WriteLine("你要存储的信息");
writer.Flush();
writer.Close();
蝶恋花雨 2012-07-25
  • 打赏
  • 举报
回复
protected void Button1_Click(object sender, EventArgs e)
{
string aa = "dddddddddddddddddddddddd";
TxtWrite(aa, @"f:\1.txt");
}
//=====================
//描述:写入TXT文件
//返回:void
private void TxtWrite(string strToWrite, string filename)
{
StreamReader sr = new StreamReader(filename, Encoding.Default);
int i = 0;//取得行数
string s;
while ((s = sr.ReadLine()) != null)
{
i++;
}
if (i > 10000)//大于10000行数的时候新建
{
//新建文件夹
string FullFileName = DateTime.Now + ".txt";
FileStream fs1 = new FileStream(FullFileName, FileMode.CreateNew);
fs1.Close();
}
else//否则就是写
{
FileStream fs = new FileStream(filename, FileMode.Create, FileAccess.Write);
StreamWriter sw = new StreamWriter(fs);
sw.BaseStream.Seek(0, SeekOrigin.Begin);
sw.WriteLine(strToWrite);
sw.Close();
}
}
c2606050113 2012-07-25
  • 打赏
  • 举报
回复
textbox是有多行的吧


string[]strs=textbox.Text.Split ('\n');
int a=(strs.Length%1000==0)?strs.Length:(strs.Length+1);
//存入的a文本个数
string[]str;
for(int i=0;i<a;i++)
{
//strs分成a个数组str,每个数组存一个文本
File.WriteAllLines("", str);
}
沉睡的老妖 2012-07-25
  • 打赏
  • 举报
回复
还是说一个文件只能保存一万个textbox里的字符串?
沉睡的老妖 2012-07-25
  • 打赏
  • 举报
回复
可以理解为从这个textbox的文本中获取的字符串...每一万个字符..写一个文件么?

110,545

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧