asp.net 操作txt文件 各位好啊,小弟我碰到一个问题, 无从下手,希望大哥大姐帮一下忙,感激不尽,我想导入txt格式文件,不会辨别文件格式,我希望判断导入的文件格式是不是 手机号码后加上逗号,例如115817942476,15817942477,这样的,我不知道怎么下手,希望各位在百忙中抽空教小弟我一下,谢谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 google:“c# csv文件读取”http://www.google.com.hk/search?client=pub-5434506002917399&prog=aff&channel=2000052003&q=c%23%20csv%E6%96%87%E4%BB%B6%E8%AF%BB%E5%8F%96 foreach(string s in File.ReadAllLines("")){string[] arr=s.Split(',');} 真感激大家的回答,我现在 if (this.FileUpload1.PostedFile != null) { string strFileName = this.FileUpload1.FileName;//获取初始文件名 int i = strFileName.LastIndexOf(".");//取得文件名中最后一个"."的索引 string strNewtext = strFileName.Substring(i+1);//获取文件扩展名 if (strFileName.Length > 0) { if (strNewtext == "txt") { DateTime now = DateTime.Now;//获取系统时间 string strContactName = now.Millisecond.ToString() + "_" + this.FileUpload1.PostedFile.ContentLength.ToString() + strNewtext;//重新为文件命名,时间毫秒部分+文件大小+扩展名 FileUpload1.PostedFile.SaveAs(Server.MapPath("..//SMS//sample//" + strContactName));// 保存文件到路径,用Server.MapPath()取当前文件的绝对目录.在asp.net里"\"必须用"\\"代替 // ClientScript.RegisterStartupScript(this.GetType(), "onkey", "alert('导入成功!');", true); //string strConnent = ""; // //string strSum = ""; //读取上传文本框中的内容: string sFileName = Server.MapPath("..//SMS//sample//" + strContactName); StreamReader srText = new StreamReader(sFileName, System.Text.Encoding.Default); //strConnent = srText.ReadLine();// //if (strConnent != null) //{ // strSum += strConnent; // strConnent = srText.ReadLine(); //} srText.BaseStream.Seek(0, SeekOrigin.Begin); System.Text.StringBuilder builder = new System.Text.StringBuilder(); while (srText.Peek() > -1) { builder.Append(srText.ReadToEnd()); } tbReceiver.Text = tbReceiver.Text + builder.ToString(); srText.Close(); } else { ClientScript.RegisterStartupScript(this.GetType(), "onkey", "alert('文件格式不正确!')", true); Response.End(); } } else { JScript.Alert(this, "请先选择文件"); return; } }无论txt文件中有什么内容都导进去了 l[align=center] 逻辑帝现身的时刻到了 关于生成静态页之后,很费解的一个问题! .NET的组件使用问题 如何获得客户端的IP?? 如何把数据库里的日期统统退后 vs.net里看aspx的页面文件,有时为什么一些常有属性多了红色波浪线,说未能找到这种属性 有关ASPnet开发的OA系统运行时总是会出随机性错误的问题 刚刚参加了微软面试,两道智力题分享给大家 一个关于DLL的基础问题 紧急求助,在线等!!!datagrid模板列中的DropDownList怎么响应事件?(用vb) 学习NET,希望大家能提供一些整站程序(源码的),供小弟学习 打酱油!怎么获取传的Id!
{
string[] arr=s.Split(',');
}
if (this.FileUpload1.PostedFile != null)
{
string strFileName = this.FileUpload1.FileName;//获取初始文件名
int i = strFileName.LastIndexOf(".");//取得文件名中最后一个"."的索引
string strNewtext = strFileName.Substring(i+1);//获取文件扩展名 if (strFileName.Length > 0)
{
if (strNewtext == "txt")
{
DateTime now = DateTime.Now;//获取系统时间
string strContactName = now.Millisecond.ToString() + "_" + this.FileUpload1.PostedFile.ContentLength.ToString() + strNewtext;//重新为文件命名,时间毫秒部分+文件大小+扩展名 FileUpload1.PostedFile.SaveAs(Server.MapPath("..//SMS//sample//" + strContactName));// 保存文件到路径,用Server.MapPath()取当前文件的绝对目录.在asp.net里"\"必须用"\\"代替
// ClientScript.RegisterStartupScript(this.GetType(), "onkey", "alert('导入成功!');", true);
//string strConnent = ""; //
//string strSum = "";
//读取上传文本框中的内容:
string sFileName = Server.MapPath("..//SMS//sample//" + strContactName);
StreamReader srText = new StreamReader(sFileName, System.Text.Encoding.Default);
//strConnent = srText.ReadLine();//
//if (strConnent != null) //{
// strSum += strConnent;
// strConnent = srText.ReadLine();
//}
srText.BaseStream.Seek(0, SeekOrigin.Begin);
System.Text.StringBuilder builder = new System.Text.StringBuilder();
while (srText.Peek() > -1)
{
builder.Append(srText.ReadToEnd());
}
tbReceiver.Text = tbReceiver.Text + builder.ToString();
srText.Close();
}
else
{
ClientScript.RegisterStartupScript(this.GetType(), "onkey", "alert('文件格式不正确!')", true);
Response.End();
}
}
else
{
JScript.Alert(this, "请先选择文件");
return; }
}
无论txt文件中有什么内容都导进去了