Template file:
" -//W3C//DTD XHTML 1.0 transitional//en " " HTTP://WWW.W3.ORG/TR/XHTML1/DTD/XHTML1-TRANSITIONAL.DTD ">"http://www.w3.org/1999/xhtml">"content-type" content="text/html; Charset=utf-8" /> <title> templates </title> $ content$</body>
The code is as follows:
/// <summary> ///Creating an HTML file/// </summary> /// <param name= "content" ></param> /// <returns></returns> Public stringUphtmlfile (stringcontent) { stringTemplateFile = Server.MapPath (".. /.. /.. /public/workplan/template.html"); stringNewFileName = Guid.NewGuid (). ToString () +". html"; stringPath = Server.MapPath (string. Format (".. /.. /.. /public/workplan/{0}/", DateTime.Now.ToString ("YYYY-MM-DD"))); if(!directory.exists (path)) {directory.createdirectory (path); } stringNewFile = path +NewFileName; File.Copy (TemplateFile, NewFile,true); FileStream myfile=NewFileStream (NewFile, FileMode.Open); StreamReader Mystreamreader=NewStreamReader (myfile, Encoding.UTF8); stringstrHTML =Mystreamreader.readtoend (); stringStroutput = strhtml. Replace ("$content $", content); Mystreamreader.close (); MyFile=NewFileStream (NewFile, FileMode.OpenOrCreate); StreamWriter SW=NewStreamWriter (myfile, Encoding.UTF8); Sw. Write (Stroutput); Sw. Close (); returnNewFileName; }
. NET creating HTML files based on templates