ASP.NET 文件操作实例

作者:互联网   出处:控件中国网   2014-11-05 19:05:18   阅读:1

ASP.NET 文件操作实例

//文件使用FileUpload打开

if (FileUpload1.HasFile)
        {
            try
            {

                        //流读取
                StreamReader sr = new StreamReader(FileUpload1.FileContent);
                while (!sr.EndOfStream)
                {
                    string single = sr.ReadLine(); //读取一行
                    char[] b = { ',', '.' };
                    string[] sims = single.Split(b);
                    if (sims.Length < 2)
                    {
                        Label6.Text=sims[0]+ " 输入格式不正确,请将号码与PUK2码用','或'.'分隔'";
                        return;
                    }
                    if (sims[0].Length != 11)
                    {
                        Label6.Text = sims[0] + " 号码位数不正确";
                        return;
                    }
                    if (ListBox1.Items.FindByText(sims[0]) != null) //在下面列表框查找重复号码
                    {
                        Label6.Text = sims[0] + "号码被重复输入";
                        return;
                    }

                    

                    string simgroup1 = SimGroupContrl.SimGrouping(sims[0]); //号码分组模块

                    ListItem li = new ListItem(sims[0] + "," + sims[1] + "," + simgroup1);//添加 单行列表项
                    ListBox1.Items.Add(li); //读一行添加一行

                }
            }
            catch(Exception ex)
            {
                Label6.Text = ex.Message;
            }
        }

 

Copyright© 2006-2015 ComponentCN.com all rights reserved.重庆磐岩科技有限公司(控件中国网) 版权所有 渝ICP备12000264号 法律顾问:元炳律师事务所
客服软件
live chat