Tuesday 20 September 2011

How to print notepad content in asp.net page

If you want to print the notepad content in the aspx page then you can do in the following ways.

Step-1 :  Take a lable on the page.
Step-2 : In the aspx.cs file add the in the above.
                          using System.IO;
Step-3 : In the page load write the following
         
              lblReadContent.Text = ReadFile(Server.MapPath("~/articles.txt"));
Step-4 : Create a function ReadFile which will return string.        
              public string ReadFile(string strFileName)
             {    
                  StreamReader fp=null;
                  string returnText;
                  try
                 {
                           fp = File.OpenText(strFileName);
                           returnText= fp.ReadToEnd();
                           fp.Close();
                 }
                catch
                {
                          returnText = "";
                }
                return returnText;
      }


0 comments:

Post a Comment