protected void btImport_Click(object sender, EventArgs e) { if (FileUpload1.HasFile) { int FileLen = FileUpload1.PostedFile.ContentLength; byte[] input = new byte[FileLen]; System.IO.Stream UpLoadStream = FileUpload1.PostedFile.InputStream; UpLoadStream.Read(input, 0, FileLen); UpLoadStream.Position = 0; System.IO.StreamReader sr = new System.IO.StreamReader(UpLoadStream, System.Text.Encoding.Default); //文件内容 string filecontent = sr.ReadToEnd().ToString(); sr.Close(); filecontent = Server.HtmlEncode(filecontent); ArrayList myAL = new ArrayList(); DataTable table1 = new DataTable(); table1.Clear(); string[] filearr = filecontent.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < filearr.Length; i++) { string[] danarr = (filearr[i]).Split(new string[] { "," }, StringSplitOptions.None); if (i == 0) { for (int j = 0; j < danarr.Length; j++) { table1.Columns.Add(danarr[j].Trim()); } } else { DataRow dr = table1.NewRow(); for (int d = 0; d < danarr.Length; d++) { dr[d] = danarr[d].ToString(); } table1.Rows.Add(dr); } } if (bll.ImportProducts(table1, Convert.ToInt32(ModelID_Hid.Value), NodeID)) { function.WriteSuccessMsg("导入成功"); } else { function.WriteErrMsg("导入失败"); } } }