sourabh choubey

sourabh choubey

  • NA
  • 174
  • 43.9k

dont use foreach loop to write xml in controller in mvc..

Jul 26 2016 3:43 AM
I don't want to use foreach loop to write the contents in xml.is there any other way so that we
can not use foreach loop inside the controller to write xml content..
Here is my code..
var blog = _api.GetAllBlogCategory().ToList();
StreamWriter writer = new StreamWriter(Server.MapPath("~/XmlFiles/BlogCategory.xml"));
writer.WriteLine(@"<?xml version=""1.0"" encoding=""utf-8""?>");
writer.WriteLine("<CategoriesBlog>");
foreach(var blogitems in blog)
{
writer.WriteLine("<CategoryBlog ID='" + blogitems.ID + "' Name='" + blogitems.Name + "' ParentId='" + blogitems.ParentID + "' Seo_Discription='" + blogitems.seo_keywords + "' Seo_KeyWords='" + blogitems.seo_keywords + "'>");
writer.WriteLine("</CategoryBlog>");
}
writer.WriteLine("</CategoriesBlog>");
writer.Close();
 

Answers (2)