各位好啊,小弟我碰到一个问题, 无从下手,希望大哥大姐帮一下忙,感激不尽,我想导入txt格式文件,不会辨别文件格式,我希望判断导入的文件格式是不是 手机号码后加上逗号,例如115817942476,15817942477,这样的,我不知道怎么下手,希望各位在百忙中抽空教小弟我一下,谢谢

解决方案 »

  1.   

    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
      

  2.   

    foreach(string s in File.ReadAllLines(""))
    {
    string[] arr=s.Split(',');
    }
      

  3.   

    真感激大家的回答,我现在
      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文件中有什么内容都导进去了
      

  4.   

    l[align=center]