How it works...

In steps 1 to 10, we opened an existing solution that contained the library for reading and writing XML files. Then, in these steps, we added an ASP.NET MVC project to that solution. In step 13, we added a reference to our library built in the previous recipe. This will allow you to access available methods from the library.

In steps 16 to 20, we added a controller to the project and named it HomeController. In step 24, we added a using directive to reference the library. In step 25, we created code to create an instance of the XMLLog class and used it in methods to create and write to the XML document. In the following line of code, we are giving the path and name of our XML file: 

var xmlFile = $"{Server.MapPath("~")}/testlog.xml";

Server.MapPath("~") guarantees the file is created at the root of our web folder. In steps 26 to 29, we confirmed our code is working and the XML file is created with the log entries. In step 30, we created a new action for our HomeController. We created an instance of the XMLLog class and used it in methods to read the information from the log file. Then we stored the values in ViewBag:

ViewBag.LogDetails = xmlLog.ReadLog();

In step 32, we created a view for the Display action, such as we did in step 22. Then we added code for the view in step 32, which converted ViewBag to a dictionary and displayed the content inside it. Finally, we tested the output in steps 34 and 35.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.19.56.45