Sponsored Ad

Wednesday, April 7, 2010

How to Write HTML File in C#

This sample code will guide you to write an html file into given path. You just need to pass the file full path and values to write on file.

 

public static bool WriteHtmlFile(string pHtmlFileNameWithFullPath, string pValue)
        {
            bool mSuccess = false;

            if (pValue.Trim().Length > 0)
            {

                try
                {
                    System.IO.StreamWriter sw = new System.IO.StreamWriter(pHtmlFileNameWithFullPath, false);

                    sw.Write(pValue);

                    sw.Close();
                }
                catch (Exception)
                {
                    Exception ex = new Exception(pHtmlFileNameWithFullPath.Substring(pHtmlFileNameWithFullPath.LastIndexOf("\\")) + " not accessible !! contact administrator..");
                    throw ex;
                }

                mSuccess = true;
            }

            return mSuccess;
        }

1 comments:

  1. I m really impressed with your work. I m glad to have read this article. It was a great way of putting forward your ideas on this subject?? I m relieved to find such good work after going through such pains in searching for the appropriate matter for my project??. Congratulations.
    Kashif Intizam
    blog.powerbrainsolutions.com

    ReplyDelete

Sponsored Ad

Website Update

Followers