473,770 Members | 1,994 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Counting code lines i asp.net project

Hi

We have a rather large asp.net project with serveral utility projects
(written in C#). Is there at tool out there which can give an estimate of
the total amount of code lines all projects results in?

thanks in regads
Anders
Nov 19 '05 #1
5 1185
I’d suggest using DPack from USysWare (http://www.usysware.com/dpack/) for
this task. With it installed, it adds a few extra items to your Tools menu
including one named ‘Solution Statistics’ which runs through all of the files
and projects that are part of your solution and lists for you to total number
of lines within, as well as how many of those lines are empty, comments or
code.

Brendan
"Anders K. Jacobsen [DK]" wrote:
Hi

We have a rather large asp.net project with serveral utility projects
(written in C#). Is there at tool out there which can give an estimate of
the total amount of code lines all projects results in?

thanks in regads
Anders

Nov 19 '05 #2
At the end of this post is a C# program I had to count all lines of code in a
single directory tree. Not exactly what you had in mind, but you could parse
through the solution files to find the particular projects you are interested
in.

I have thought about going back through the code and making a Visual Studio
add in, but I am wracked at this time. I am sure there are code metric tools
that are far better than this.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

*************** ************
Think Outside the Box!
*************** ************
"Anders K. Jacobsen [DK]" wrote:
Hi

We have a rather large asp.net project with serveral utility projects
(written in C#). Is there at tool out there which can give an estimate of
the total amount of code lines all projects results in?

thanks in regads
Anders


/* CODE SAMPLE *************** *************** ************/
using System;
using System.Drawing;
using System.Collecti ons;
using System.Componen tModel;
using System.Windows. Forms;
using System.Data;
using System.IO;

namespace LineCounter
{
public class Form1 : System.Windows. Forms.Form
{
private System.Windows. Forms.Button btnRun;
private System.Windows. Forms.TextBox txtDirectory;
private System.Componen tModel.Containe r components = null;

public Form1()
{
InitializeCompo nent();
}

protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Disp ose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
private void InitializeCompo nent()
{
this.btnRun = new System.Windows. Forms.Button();
this.txtDirecto ry = new System.Windows. Forms.TextBox() ;
this.SuspendLay out();
//
// btnRun
//
this.btnRun.Loc ation = new System.Drawing. Point(8, 40);
this.btnRun.Nam e = "btnRun";
this.btnRun.Tab Index = 0;
this.btnRun.Tex t = "Run";
this.btnRun.Cli ck += new System.EventHan dler(this.btnRu n_Click);
//
// txtDirectory
//
this.txtDirecto ry.Location = new System.Drawing. Point(8, 8);
this.txtDirecto ry.Name = "txtDirecto ry";
this.txtDirecto ry.Size = new System.Drawing. Size(256, 20);
this.txtDirecto ry.TabIndex = 1;
this.txtDirecto ry.Text = "C:\\Projects\\ SOURCE_SAFE\\Co de\\AIMHealth";
//
// Form1
//
this.AutoScaleB aseSize = new System.Drawing. Size(5, 13);
this.ClientSize = new System.Drawing. Size(292, 266);
this.Controls.A dd(this.txtDire ctory);
this.Controls.A dd(this.btnRun) ;
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayo ut(false);

}
#endregion

[STAThread]
static void Main()
{
Application.Run (new Form1());
}

private long _totalCount=0;
StreamWriter _sw = new StreamWriter(@" C:\temp\counts. txt");
private char[] _split = { '\\' };

private void btnRun_Click(ob ject sender, System.EventArg s e)
{
_totalCount=0;

//Write out header
_sw.WriteLine(" Directory|File| File Line Count|Directory Line Count");

//Get the starting directory
string startDir = txtDirectory.Te xt;
//startDir = @"C:\Projects\T emp\DataTest\Da taTest";

//Set up the total count
_totalCount += GetLinesForDire ctory(startDir) ;

//Write out footer
_sw.WriteLine(" TOTAL||||"+_tot alCount.ToStrin g());
_sw.Flush();
_sw.Close();

MessageBox.Show (_totalCount.To String());
}

private long GetLinesForDire ctory(string directoryPath)
{
DirectoryInfo di = new DirectoryInfo(d irectoryPath);
long directoryCount = 0;

//Directories
foreach(Directo ryInfo d in di.GetDirectori es())
{
_totalCount += GetLinesForDire ctory(d.FullNam e);
}

//Files
foreach(FileInf o f in di.GetFiles())
{
if((f.Extension ==".cs")||(f.Ex tension==".asax ")||(f.Extensio n==".aspx")||(f .Extension==".a smx")||(f.Exten sion==".ascx"))
directoryCount += GetLinesForFile (f.FullName, directoryPath);
}

//Write out the line
if(directoryCou nt!=0)
{
_sw.WriteLine(d irectoryPath+"| ||"+directoryCo unt.ToString()) ;
}

return directoryCount;
}

private long GetLinesForFile (string filePath, string directoryPath)
{
long counter=0;
string line;
StreamReader sr = new StreamReader(fi lePath);
string[] fileBroken = null;

while(sr.Peek() >=0)
{
line=sr.ReadLin e().Trim();

if(line.Length> 0)
{
if((line.Substr ing(0,1)!=@"/")&&(line.Subst ring(0,1)!=@"*" )&&(line.Substr ing(0,1)!=@"#") )
counter++;
}
}

if(counter!=0)
{
fileBroken = filePath.Split( _split);

_sw.WriteLine(d irectoryPath+"| "+fileBroke n[fileBroken.Leng th-1]+"|"+counter.To String());
}

return counter;
}
}
}

Nov 19 '05 #3
PErfect !
"Brendan Grant" <gr****@NOSPAMd ahat.com> skrev i en meddelelse
news:44******** *************** ***********@mic rosoft.com...
I'd suggest using DPack from USysWare (http://www.usysware.com/dpack/) for
this task. With it installed, it adds a few extra items to your Tools menu
including one named 'Solution Statistics' which runs through all of the
files
and projects that are part of your solution and lists for you to total
number
of lines within, as well as how many of those lines are empty, comments or
code.

Brendan
"Anders K. Jacobsen [DK]" wrote:
Hi

We have a rather large asp.net project with serveral utility projects
(written in C#). Is there at tool out there which can give an estimate of
the total amount of code lines all projects results in?

thanks in regads
Anders

Nov 19 '05 #4
> including one named 'Solution Statistics' which runs through all of
the files
and projects that are part of your solution and lists for you to
total number
of lines within, as well as how many of those lines are empty,
comments or
code.


To add to Brendan's reply, you could also copy the stats dialog
contents to the clipboard via Ctrl-C. I find it useful if I need to
share the results with somebody.
--
Sergey Mishkovskiy
http://www.usysware.com/dpack/ - DPack - free VS.NET add-ons
http://www.usysware.com/blog/

Nov 19 '05 #5
There is a Statistics feature in my add-in (below). It counts code lines,
comment lines, total lines, percentages, classes, functions and so on...

--
Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio .NET, VB6, VB5 and VBA
You can code, design and document much faster.
Free resources for add-in developers:
http://www.mztools.com

"Anders K. Jacobsen [DK]" <no**@at.all> escribió en el mensaje
news:uO******** *****@TK2MSFTNG P15.phx.gbl...
Hi

We have a rather large asp.net project with serveral utility projects
(written in C#). Is there at tool out there which can give an estimate of
the total amount of code lines all projects results in?

thanks in regads
Anders

Nov 19 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
3111
by: Dale Atkin | last post by:
As part of a larger project, I need to be able to count the number of lines in a file (so I know what to expect). Anyways, I came accross the following code that seems to do the trick, the only thing is, I'm not 100% sure what it is doing, or how. #include<iostream> #include<fstream> main(int argc, char *argv) {
1
1404
by: VM | last post by:
How can I know how many lines of code are in my solution (which consists of two projects)? Thanks.
5
2848
by: Anders K. Jacobsen [DK] | last post by:
Hi We have a rather large asp.net project with serveral utility projects (written in C#). Is there at tool out there which can give an estimate of the total amount of code lines all projects results in? thanks in regads Anders
1
6929
by: j | last post by:
Hi, I've been trying to do line/character counts on documents that are being uploaded. As well as the "counting" I also have to remove certain sections from the file. So, firstly I was working with uploaded MS WORD .doc files. Using code like that below: strLine = sr.ReadLine While Not IsNothing(strLine) 'Not eof If Trim(strLine) <> "" Then 'Not blank
4
1816
by: Peter | last post by:
Currently I'm using the method below, is there someting more efficient?: Imports System.IO Public Class CountLine Public Shared Function CountLines(ByVal FileName As String) As Integer Dim fs As IO.FileStream Dim sr As IO.StreamReader Dim Result As Integer Try fs = New IO.FileStream( _
5
7705
by: andy.lee23 | last post by:
hi im having trouble counting lines in a text file, i have the following code int node1, node2, i; char name; float value; ifstream fin; fin.open(OpenDialog1->FileName.c_str()); i=1;
10
1517
by: cj | last post by:
I'm writing a TCP/IP server app that will have many simultaneous connections. The main thread listens for new connections and starts a thread to handle each requested connection. These are short lived threads that get a request and return a reply and end. Can the main thread tell me how many connection threads are currently running at any given time? I'd like to have a label on the main form to show how many connections the server is...
14
2092
by: Dan | last post by:
Is this discouraged?: for line in open(filename): <do something with line> That is, should I do this instead?: fileptr = open(filename) for line in fileptr: <do something with line>
7
2116
by: peraklo | last post by:
Hello, there is another problem i am facing. i have a text file which is about 15000 lines big. i have to cut the last 27 lines from that file and create a new text file that contans those 27 lines. and after that save both of those files... since that is a big block of text (15000 lines) i thint that it is a big job to look for a keyword... so my question is this exactly: how do i do this:
1
2429
by: powerej | last post by:
I have gotten the part of counting how many words are in the string, but the vowels just seem alien to me. Ive tried so many things but never close to a correct answer. I know I need to use charAt() and length() some nested loops with do while and for, but cant seem to get headed in the right direction. Also when i click the cancel button my program is suppose to end and tell you how many lines were entered, a count of vowels from all lines...
0
10259
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10101
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10038
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8933
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7456
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6710
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.