protected int GetAndStoreRefTable(string tableName, string ValueString, string TextString, string CustomParseName) { try { //get file DomainValuesService d = new DomainValuesService(); XDocument xdoc = null; byte[] b = d.GetDomainValues(tableName); using (System.IO.Stream stream = new System.IO.MemoryStream(b)) { using (var zip = ZipFile.Read(stream)) { foreach (var entry in zip) { //cleanup any previous files if (File.Exists(Server.MapPath("~/tmp/" + entry.FileName))) { File.Delete(Server.MapPath("~/tmp/" + entry.FileName)); } entry.Extract(Server.MapPath("~/tmp")); xdoc = XDocument.Load(Server.MapPath("~/tmp/" + entry.FileName)); } } } // ***************** DEFAULT PARSING ************************************** if (CustomParseName == null) { var lv1s = from lv1 in xdoc.Descendants("{http://www.exchangenetwork.net/schema/wqx/2}WQXElementRow") select new { ID = lv1.Descendants("{http://www.exchangenetwork.net/schema/wqx/2}WQXElementRowColumn").First(ID2 => ID2.Attribute("colname").Value == ValueString).Attribute("value"), Text = lv1.Descendants("{http://www.exchangenetwork.net/schema/wqx/2}WQXElementRowColumn").First(Text2 => Text2.Attribute("colname").Value == TextString).Attribute("value"), }; foreach (var lv1 in lv1s) { db_Ref.InsertOrUpdateT_WQX_REF_DATA(tableName, lv1.ID.Value, lv1.Text.Value, null); } } // ***************** CUSTOM PARSING for CHARACTERSTIC ************************************** else if (CustomParseName == "Characteristic") { var lv1s = from lv1 in xdoc.Descendants("{http://www.exchangenetwork.net/schema/wqx/2}WQXElementRow") select new { ID = lv1.Descendants("{http://www.exchangenetwork.net/schema/wqx/2}WQXElementRowColumn").First(ID2 => ID2.Attribute("colname").Value == ValueString).Attribute("value"), SampFracReq = lv1.Descendants("{http://www.exchangenetwork.net/schema/wqx/2}WQXElementRowColumn").First(Text2 => Text2.Attribute("colname").Value == "SampleFractionRequired").Attribute("value"), PickList = lv1.Descendants("{http://www.exchangenetwork.net/schema/wqx/2}WQXElementRowColumn").First(Text2 => Text2.Attribute("colname").Value == "PickList").Attribute("value") }; foreach (var lv1 in lv1s) { db_Ref.InsertOrUpdateT_WQX_REF_CHARACTERISTIC(lv1.ID.Value, null, null, null, true, lv1.SampFracReq.Value, lv1.PickList.Value); } } // ***************** CUSTOM PARSING for ANALYTICAL METHOD ************************************** else if (CustomParseName == "AnalMethod") { var lv1s = from lv1 in xdoc.Descendants("{http://www.exchangenetwork.net/schema/wqx/2}WQXElementRow") select new { ID = lv1.Descendants("{http://www.exchangenetwork.net/schema/wqx/2}WQXElementRowColumn").First(ID2 => ID2.Attribute("colname").Value == "ID").Attribute("value"), Name = lv1.Descendants("{http://www.exchangenetwork.net/schema/wqx/2}WQXElementRowColumn").First(Text2 => Text2.Attribute("colname").Value == "Name").Attribute("value"), CTX = lv1.Descendants("{http://www.exchangenetwork.net/schema/wqx/2}WQXElementRowColumn").First(CTX2 => CTX2.Attribute("colname").Value == "ContextCode").Attribute("value"), Desc = lv1.Descendants("{http://www.exchangenetwork.net/schema/wqx/2}WQXElementRowColumn").First(Desc2 => Desc2.Attribute("colname").Value == "Description").Attribute("value"), }; foreach (var lv1 in lv1s) { db_Ref.InsertOrUpdateT_WQX_REF_ANAL_METHOD(null, lv1.ID.Value, lv1.CTX.Value, lv1.Name.Value, lv1.Desc.Value, true); } } // ***************** CUSTOM PARSING for COUNTY ************************************** else if (CustomParseName == "County") { var lv1s = from lv1 in xdoc.Descendants("{http://www.exchangenetwork.net/schema/wqx/2}WQXElementRow") select new { ID = lv1.Descendants("{http://www.exchangenetwork.net/schema/wqx/2}WQXElementRowColumn").First(ID2 => ID2.Attribute("colname").Value == "CountyFIPSCode").Attribute("value"), Text = lv1.Descendants("{http://www.exchangenetwork.net/schema/wqx/2}WQXElementRowColumn").First(Text2 => Text2.Attribute("colname").Value == "CountyName").Attribute("value"), State = lv1.Descendants("{http://www.exchangenetwork.net/schema/wqx/2}WQXElementRowColumn").First(Text2 => Text2.Attribute("colname").Value == "StateCode").Attribute("value"), }; foreach (var lv1 in lv1s) { db_Ref.InsertOrUpdateT_WQX_REF_COUNTY(lv1.State.Value, lv1.ID.Value, lv1.Text.Value, null); } } return(1); } catch (Exception e) { lblMsg.Text = "Error" + e.Message; return(0); } }