private void button3_Click(object sender, EventArgs e)
{
    try
    {
        ArrayList TwoList = new ArrayList();
        openFileDialog1.InitialDirectory = Application.StartupPath;
        openFileDialog1.Filter = "文本文件|*.txt";
        if (openFileDialog1.ShowDialog() == DialogResult.OK)
        {
            string fileName = openFileDialog1.FileName;
            using (FileStream fs = new FileStream(fileName, FileMode.Open))
            {
                using (StreamReader sr = new StreamReader(fs, Encoding.Default))
                {
                    while (!sr.EndOfStream)
                    {
                        string sLine = sr.ReadLine();
                        if (sLine.Length < 1)
                            continue;
                        string[] sRecord = sLine.Split('\t');
                        if (sRecord[4] == "2")
                            TwoList.Add(sRecord);
                    }
                }
            }
             //这里是重点代码,上边都是取数据的。
            int count = 0;
            int count1 = 0;
            int count2 = 0;
            foreach (string[] item in TwoList)
            {
                DataRow dr = GetStuData(item[0], item[1]);
                if (dr != null)
                {
                    count1++;
                    continue;
                }
                //在这里循环创建XML文件,问题就是出现在这里。
                //提示创建成功了355个,可是去XML目录里面看了下,只生成了3个。
                bool isOk = CreateXmlInfo(item[0], item[1], GetProductCode(item[6]));
                if (isOk)
                    count++;
                else
                    count2++;
            }
            MessageBox.Show("创建报文成功!共" + TwoList.Count + "个,跳过" + count1 + "个,失败" + count2 + "个,成功" + count + "个", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
        }
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
        return;
    }
}下面是创建XML的代码。public bool CreateXmlInfo(string groupId, string telNum, string productCode)
{
    if (productCode == "")
        return false;
    try
    {
        string xmlFileName = "SIBOSSECBIZ_" + DateTime.Now.ToString("yyyyMMddHHmmss");
        XmlDocument xml = new XmlDocument();
        XmlDeclaration xmlDecl;
        xmlDecl = xml.CreateXmlDeclaration("1.0", "UTF-8", null);
        xml.AppendChild(xmlDecl);
        XmlElement xmlElem;
        xmlElem = xml.CreateElement("InterADC");
        XmlElement FileSeq = xml.CreateElement("FileSeq");
        FileSeq.InnerText = DateTime.Now.ToString("yyyyMMddHHmmss");
        xmlElem.AppendChild(FileSeq);
        xml.AppendChild(xmlElem);
        XmlNode InterADC = xml.SelectSingleNode("InterADC");        XmlElement OrdData = xml.CreateElement("OrdData");
        XmlElement ECID = xml.CreateElement("ECID");
        ECID.InnerText = groupId;
        XmlElement OrdTime = xml.CreateElement("OrdTime");
        OrdTime.InnerText = GetOrdTime(groupId);
        OrdData.AppendChild(ECID);
        OrdData.AppendChild(OrdTime);
        XmlElement ECInfo = xml.CreateElement("ECInfo");
        XmlElement ProdID = xml.CreateElement("ProdID");
        ProdID.InnerText = "AHA3919901";
        ECInfo.AppendChild(ProdID);
        DateTime ApplyTimeNow = DateTime.Now;
        XmlElement ChildECInfo = xml.CreateElement("ChildECInfo");
        XmlElement ChildECID = xml.CreateElement("ChildECID");
        ChildECID.InnerText = telNum;
        XmlElement OprCode = xml.CreateElement("OprCode");
        OprCode.InnerText = "04";
        XmlElement FeeTime = xml.CreateElement("FeeTime");
        FeeTime.InnerText = ApplyTimeNow.ToString("yyyyMMddHHmmss");
        XmlElement Price = xml.CreateElement("Price");
        Price.InnerText = productCode;
        XmlElement SignFlag = xml.CreateElement("SignFlag");
        SignFlag.InnerText = "1";
        XmlElement IsSecondConfirm = xml.CreateElement("IsSecondConfirm");
        IsSecondConfirm.InnerText = "0";        ChildECInfo.AppendChild(ChildECID);
        ChildECInfo.AppendChild(OprCode);
        ChildECInfo.AppendChild(FeeTime);
        ChildECInfo.AppendChild(Price);
        ChildECInfo.AppendChild(SignFlag);
        ChildECInfo.AppendChild(IsSecondConfirm);
        ECInfo.AppendChild(ChildECInfo);        OrdData.AppendChild(ECInfo);
        InterADC.AppendChild(OrdData);        string path = Application.StartupPath + "\\XMLFile\\";
        if (!Directory.Exists(path))
            Directory.CreateDirectory(path);
        xml.Save(path + xmlFileName);
        xml = null;//我怀疑问题是不是出现在这里了,为什么执行了却没有生成文件呢。
        return true;
    }
    catch (Exception e)
    {
        MessageBox.Show(e.Message);
        return false;
    }
}
如图,提示的数据是对的,就是在循环里面确实调用了355次创建XML的方法,但只生成了三个XML文件,其它的文件都没有生成。
求大神...