public JsonResult ImportCodes(HttpPostedFileBase file) { try { XmlDocument codes = new XmlDocument(); codes.Load(file.InputStream); StringBuilder sb = new StringBuilder(); List <TemporarySnippet> tmpSnippets = new List <TemporarySnippet>(); foreach (XmlNode xmlNode in codes.DocumentElement) { TemporarySnippet tmpSnippet = new TemporarySnippet(); foreach (XmlNode innerNode in xmlNode) { if (innerNode.Name.Equals("code")) { tmpSnippet.Code = innerNode.InnerText; } else { tmpSnippet.Output = innerNode.InnerText; } } tmpSnippets.Add(tmpSnippet); } bool result = _snippetService.AddTemporarySnippets(tmpSnippets); if (result) { return(Json("Success")); } return(Json("Error")); } catch { return(Json("Check the XML format")); } }