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;
}
}