Subscribe to Subscribers
Talk to Webmaster Tony John

Resources » Code Snippets » File Operations

How to capture all the comments from class files (.cs) using C#?


Posted Date:     Category: File Operations    
Author: Member Level: Gold    Points: 10


User can maintain a log for all comments present in the class file. This will be used for maintainance purpose. Clean up activities can be done on basis of comments log. User can add/delete required comments data. You can also put different filters. I hope it will be useful.



 


How to capture all the comments from class files (.cs) using C#?
Concept description: User has to browse one class file (.cs) after clicking on button1. Code is used to read all file contents and find out whether comments are present in the file or not.
If comments are present in the file then it will capture it in Comments_logger.txt file which will be saved at D:\\Comments_logger.txt
Instead of hardcoded path for logger file, you can use web.config file and read the path by using configuration setting as well.

private void button1_Click(object sender, EventArgs e)
{
List lst = new List();
openFileDialog1.ShowDialog();
textBox1.Text = openFileDialog1.FileName;

using (StreamReader sr = new StreamReader(textBox1.Text))
{
String line;
while ((line = sr.ReadLine()) != null)
{
if (line.Trim().StartsWith("//"))
{
lst.Add(line + "\n");
}
}
}
using (StreamWriter outfile = new StreamWriter("D:\\" + "Comments_logger.txt"))
{
foreach (string str in lst)
{
outfile.Write(str + "\n");
}
}

}






Did you like this resource? Share it with your friends and show your love!


Responses to "How to capture all the comments from class files (.cs) using C#?"

No responses found. Be the first to respond...

Feedbacks      

Post Comment:




  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)



    Type the numbers and letters shown on the left.


    Next Resource: How to maintain the log file to track application performance using C#?
    Previous Resource: Search if text is present in a file
    Return to Resources
    Post New Resource
    Category: File Operations


    Post resources and earn money!
     
    More Resources
    Popular Tags   Tag posting guidelines   Search Tags  
    (No tags found.)
    Active Members
    TodayLast 7 Daysmore...

    Awards & Gifts
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
    2005 - 2012 All Rights Reserved.
    .NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
    Articles, tutorials and all other content offered here is for educational purpose only.
    We are not associated with Microsoft or its partners.