protected void btn_Click(object sender, EventArgs e) { try { DataSet DsSub = new DataSet(); string JourneyDate = txtDate.Text.ToString(); BitlaAPI objbitla = new BitlaAPI(); IBitlaAPILayer objBitlaAPILayer = null; objBitlaAPILayer = new BitlaAPILayer(); objBitlaAPILayer.URL = BitlaConstants.URL; objBitlaAPILayer.ApiKey = BitlaConstants.API_KEY; objBitlaAPILayer.Date = JourneyDate; DataSet dsBitlaAllAvailableRoutes = null; dsBitlaAllAvailableRoutes = objbitla.GetAllAvailableRoutes(objBitlaAPILayer.URL,objBitlaAPILayer.ApiKey, objBitlaAPILayer.Date); dsBitlaAllAvailableRoutes.WriteXml(Server.MapPath("~/Routes/" + JourneyDate + ".xml")); lblMsg.Text = " Submitted. "; XmlDataDocument XmlDocRef = new XmlDataDocument(); // StreamWriter XmlDataRef = new StreamWriter(Path.Combine(HttpRuntime.AppDomainAppPath, "App_Data\\XMLfiles\\" + "RefCallback.xml"), false); XmlDocRef.Load(Path.Combine(HttpRuntime.AppDomainAppPath, "App_Data\\XMLfiles\\" + "RefCallback.xml")); foreach (DataRow row in dsBitlaAllAvailableRoutes.Tables[1].Rows) { string DirectoryPath = Server.MapPath("~/App_Data/XMLfiles"); DirectoryInfo dir = new DirectoryInfo(DirectoryPath); if (!dir.Exists) { dir.Create(); } string filepath = "~/App_Data/XMLfiles/" + "RefCallback.xml"; string DirectoryPath1 = Server.MapPath(filepath); DirectoryInfo dir1 = new DirectoryInfo(DirectoryPath1); if (dir1.Exists == true) { DataSet ds1 = new DataSet(); DataTable dt = new DataTable("Refcal"); dt.Columns.Add("Date"); dt.Columns.Add("id"); dt.Columns.Add("travel_id"); dt.Columns.Add("reservation_id"); DataRow dr1; dr1 = dt.NewRow(); dr1["Date"] = JourneyDate; dr1["id"] = row["reservation_id"]; dr1["travel_id"] = row["travel_id"]; dr1["reservation_id"] = row["reservation_id"]; dt.Rows.Add(dr1); ds1.Tables.Add(dt); ds1.EnforceConstraints = false; XmlDataDocument XmlDoc = new XmlDataDocument(ds1); // Write down the XML declaration // XmlDeclaration xmlDeclaration = XmlDoc.CreateXmlDeclaration("1.0", "utf-8", null); // Create the root element //XmlElement rootNode = XmlDoc.CreateElement("CallBack"); //XmlDoc.InsertBefore(xmlDeclaration, XmlDoc.DocumentElement); // XmlDoc.AppendChild(rootNode); XmlDoc.Save(Server.MapPath(filepath)); } else { //create node and add value XmlNode node = XmlDocRef.CreateNode(XmlNodeType.Element, "Refcal", null); node.InnerXml = "<Date>" + JourneyDate + "</Date><id>" + row["id"] + "</id><travel_id>" + row["travel_id"] + "</travel_id><reservation_id>" + row["reservation_id"] + "</reservation_id>"; //add to elements collection XmlDocRef.DocumentElement.AppendChild(node); //DsSub.ReadXml(Server.MapPath("~/App_Data/XMLfiles/" + "RefCallback.xml")); //DataRow dr; //dr = DsSub.Tables[0].NewRow(); //dr["Date"] = JourneyDate; //dr["id"] = row["id"]; //dr["travel_id"] = row["travel_id"]; //dr["reservation_id"] = row["reservation_id"]; //DsSub.Tables[0].Rows.Add(dr); } } XmlDocRef.Save(Path.Combine(HttpRuntime.AppDomainAppPath, "App_Data\\XMLfiles\\" + "RefCallback.xml")); //DataSet ds2 = new DataSet(); //ds2.EnforceConstraints = false; //XmlDataDocument XmlDoc1 = new XmlDataDocument(ds2); //StreamWriter XmlData1 = new StreamWriter(Server.MapPath("~/App_Data/XMLfiles/" + "RefCallback.xml"), false); //DsSub.WriteXml(XmlData1); //XmlData1.Close(); } catch (Exception) { // throw; } }