private StudentXxe DeserializeStudent(string xml) { var student = new StudentXxe(); TextReader textReader = new StringReader(xml); var settings = new XmlReaderSettings { DtdProcessing = DtdProcessing.Parse }; var serializer = new XmlSerializer(typeof(StudentXxe)); using (var xmlReader = XmlReader.Create(textReader, settings)) { student = (StudentXxe)serializer.Deserialize(xmlReader); } return(student); }
public ActionResult UploadFile(HttpPostedFileBase file) { try { var student = new StudentXxe(); if (file.ContentLength > 0) { string xmlText = new StreamReader(file.InputStream).ReadToEnd(); student = DeserializeStudent(xmlText); } ViewBag.Message = "File Uploaded Successfully!!"; return(View("Index", student)); } catch (Exception ex) { ViewBag.Message = "File upload failed!!"; return(View("Index")); } }
// GET: XmlExternalEntities public ActionResult Index() { var student = new StudentXxe(); return(View(student)); }