Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Jul 10, 2012 07:47 AM by gokhaled89
Member
6 Points
30 Posts
Jul 10, 2012 06:09 AM|LINK
Hi,
Can anyone tell me how to store the object read from the database using entity framework into an xml file?
And then how to read and update that file.
92 Points
36 Posts
Jul 10, 2012 07:03 AM|LINK
public void WriteXML() { writetoXML(DateTime.Today.ToShortDateString(), DateTime.Now.ToString(), newfilename, System.Net.Dns.GetHostEntry(HttpContext.Current.Request.UserHostAddress).HostName, HttpContext.Current.Request.ServerVariables["AUTH_USER"], msg, dtdate.ToShortDateString() ); } /// <summary> /// Write Logs to the XML File /// </summary> /// <param name="dtdate">System Date</param> /// <param name="timeStamp">Time Stamp</param> /// <param name="fileName">File Name</param> /// <param name="workStation">Work Station</param> /// <param name="userName"> User Name </param> /// <param name="errorlog">Error Log</param> /// <param name="operationDate">Date of Operation</param> public void writetoXML(string dtdate, string timeStamp, string fileName, string workStation, string userName, string errorlog, string operationDate) { string savepath = HttpContext.Current.Request.MapPath(HttpContext.Current.Request.ApplicationPath) + "\\ "; string xmlFileName = "Logs.xml"; string xmlPath = savepath + "\\" + xmlFileName; // determine if the file exist if (!File.Exists(xmlPath)) { // we will create new xml file XElement xml = new XElement("Logs", new XElement("Log", new XElement("Date", dtdate), new XElement("TimeStamp", timeStamp), new XElement("FileName", fileName), new XElement("WorkStation", workStation), new XElement("UserName", userName), new XElement("Error", errorlog), new XElement("OperationDate", operationDate) ) ); xml.Save(xmlPath); } else { // load the xml file and update it XDocument xmlDoc = XDocument.Load(savepath + "\\" + xmlFileName); xmlDoc.Element("Logs").Add(new XElement("Log", new XElement("Date", dtdate), new XElement("TimeStamp", timeStamp), new XElement("FileName", fileName), new XElement("WorkStation", workStation), new XElement("UserName", userName), new XElement("Error", errorlog), new XElement("OperationDate", operationDate))); xmlDoc.Save(xmlPath); } }
Jul 10, 2012 07:47 AM|LINK
Thanks a lot.. It works..
Can it be used in MVC 3 applications?
gokhaled89
Member
6 Points
30 Posts
Xml file: Reading and writing.
Jul 10, 2012 06:09 AM|LINK
Hi,
Can anyone tell me how to store the object read from the database using entity framework into an xml file?
And then how to read and update that file.
nuttynuts
Member
92 Points
36 Posts
Re: Xml file: Reading and writing.
Jul 10, 2012 07:03 AM|LINK
public void WriteXML() { writetoXML(DateTime.Today.ToShortDateString(), DateTime.Now.ToString(), newfilename, System.Net.Dns.GetHostEntry(HttpContext.Current.Request.UserHostAddress).HostName, HttpContext.Current.Request.ServerVariables["AUTH_USER"], msg, dtdate.ToShortDateString() ); } /// <summary> /// Write Logs to the XML File /// </summary> /// <param name="dtdate">System Date</param> /// <param name="timeStamp">Time Stamp</param> /// <param name="fileName">File Name</param> /// <param name="workStation">Work Station</param> /// <param name="userName"> User Name </param> /// <param name="errorlog">Error Log</param> /// <param name="operationDate">Date of Operation</param> public void writetoXML(string dtdate, string timeStamp, string fileName, string workStation, string userName, string errorlog, string operationDate) { string savepath = HttpContext.Current.Request.MapPath(HttpContext.Current.Request.ApplicationPath) + "\\ "; string xmlFileName = "Logs.xml"; string xmlPath = savepath + "\\" + xmlFileName; // determine if the file exist if (!File.Exists(xmlPath)) { // we will create new xml file XElement xml = new XElement("Logs", new XElement("Log", new XElement("Date", dtdate), new XElement("TimeStamp", timeStamp), new XElement("FileName", fileName), new XElement("WorkStation", workStation), new XElement("UserName", userName), new XElement("Error", errorlog), new XElement("OperationDate", operationDate) ) ); xml.Save(xmlPath); } else { // load the xml file and update it XDocument xmlDoc = XDocument.Load(savepath + "\\" + xmlFileName); xmlDoc.Element("Logs").Add(new XElement("Log", new XElement("Date", dtdate), new XElement("TimeStamp", timeStamp), new XElement("FileName", fileName), new XElement("WorkStation", workStation), new XElement("UserName", userName), new XElement("Error", errorlog), new XElement("OperationDate", operationDate))); xmlDoc.Save(xmlPath); } }gokhaled89
Member
6 Points
30 Posts
Re: Xml file: Reading and writing.
Jul 10, 2012 07:47 AM|LINK
Thanks a lot.. It works..
Can it be used in MVC 3 applications?