I have a linq/xml statement that I'm splitting of of a tab. If the column is empty in the excel file, then I get an Input string is not in the correct format. Is there a way to get around this? I tried checking for string.empty in my XElement, but that's not working:
var xmlFile = new XElement("Package", from str in mainList let fields = str.Split('\t') select new XElement("Record", new XElement("recordId", FileId), new XElement("LineId", (lineId++).ToString()), new XElement("amount", (fields[21].Trim() == string.Empty ? Decimal.Parse("0.00").ToString() : Decimal.Parse(fields[21].Replace("\"", string.Empty).Trim(), NumberStyles.Currency).ToString())) ) );