Search for Stored Procedures in source code

During the development process of an ASP.NET web application, the number of
stored procedures used can grow alarmingly. More often than not, I forget to
document
which stored procedures are being used and which are redundant. So, I decided
to build a little utility that searched through my source code to find all
instances of stored procedures being used.
My goal was to have a web page that listed the procedures being used on each
page. In IE6, I could then right-click on the table and export the list to
Excel. Useful for future documentation.

First of all we start by looping through directories in our root folder:

		private string FileTypes="*.cs";
		private void DirSearch(string Dir) 
		{
			try	
			{
				foreach (string f in Directory.GetFiles(Dir, FileTypes)) 
				{
					ReadFile(f);
				}
				foreach (string d in Directory.GetDirectories(Dir)) 
				{
					DirSearch(d);
				}
			}
			catch (Exception e)
			{
				Response.Write(e.Message);
			}
		}

Like many other, all my stored procedures begin with “sp”, so we can read
each file and look for all instances of “sp*” and store them in a datatable.

		private string SearchExpression="\"(sp[^\"]+)\"";
		private void ReadFile(string fn)
		{
			StreamReader s = new StreamReader(fn);
			string read = s.ReadToEnd();
			s.Close();
			Regex r = new Regex(SearchExpression);
			MatchCollection mc=r.Matches(read);
			foreach (Match m in mc) 
			{    
				DataRow dr=dt.NewRow();
				dr["SP"]=m.Groups[1];
				dr["Page"]=fn.Substring(Folder.Length+1);
				dt.Rows.Add(dr);
			}
		}

Next, we can bind the Datatable to a Datagrid:

		private string Folder=@"c:\mywebsite";
		private void BindData()
		{
			dt=new DataTable();
			dt.Columns.Add("SP");
			dt.Columns.Add("Page");
			DirSearch(Folder);
			DataView dv=dt.DefaultView;
			dv.Sort=SortColumn;
			DataGrid1.DataSource=dv;
			DataGrid1.DataBind();
		}

And then bring it all together when the pages loads:

		private void Page_Load(Object src,EventArgs e) 
		{
			if (!IsPostBack)
			{
				SortColumn="SP";
				BindData();
			}
		}
Updated: March 5, 2015 — 11:06 pm

Comments

Add a Comment
  1. Your comment is awaiting moderation.

    You suggested it really well!
    https://www.lunarciel.com/
    canada pharmacies without script
    northwest pharmacy
    discount pharmacy online
    canadian pharmacy

  2. Your comment is awaiting moderation.

    Truly quite a lot of fantastic tips!
    https://www.lunarciel.com/
    canadian pharmacies online prescriptions
    canada pharmaceuticals online
    prescription drug assistance
    northwest pharmacy

  3. Your comment is awaiting moderation.

    Excellent forum posts. Appreciate it.
    https://www.waltcoexpress.com/
    canadapharmacyonline.com
    canadian pharcharmy
    most reliable canadian pharmacies
    canadian pharmacies without an rx

  4. Your comment is awaiting moderation.

    Valuable tips. Thank you!
    https://www.interlandchemie.com/
    canadian prescription drugs
    north west pharmacy canada
    canadian pharma companies
    canada drugs online

  5. Your comment is awaiting moderation.

    You have made your point!
    https://www.lunarciel.com/
    costco pharmacy pricing
    canadian pharmacy online
    compare rx prices
    canadian drugs

  6. Your comment is awaiting moderation.

    Many thanks, An abundance of posts!

    https://www.lunarciel.com/
    canadian pharmacy no prescription needed
    canadian drugs
    cheap drugs online
    canada drugs

  7. Your comment is awaiting moderation.

    You actually suggested this exceptionally well.
    https://www.visitwaushara.com/
    canadian pharmacy meds
    canadian viagra
    prescription pricing
    aarp approved canadian online pharmacies

  8. Your comment is awaiting moderation.

    Really a good deal of awesome facts.
    https://www.dunamisproductions.com/
    canadian pharmacy meds
    canadian cialis
    canada drugs
    canadian pharmacy online

  9. Your comment is awaiting moderation.

    You explained it really well!
    https://www.dunamisproductions.com/
    drugs without prescription
    canada online pharmacies
    canadian prescription drugstore
    canadian pharmacy

  10. Your comment is awaiting moderation.

    Awesome forum posts. Thank you!
    https://www.dunamisproductions.com/
    top rated online canadian pharmacies
    canadian pharmacies online
    prescription price comparison
    canadian pharmacies online

  11. Your comment is awaiting moderation.

    Many thanks, Great information.
    https://www.waltcoexpress.com/
    best online international pharmacies
    canadian pharmacy
    canadian pharcharmy online
    canada pharmaceuticals online

  12. Your comment is awaiting moderation.

    Nicely put, Regards.
    https://www.visitwaushara.com/
    canada meds
    canadian drugs
    candrugstore com
    canadian drugs

  13. Your comment is awaiting moderation.

    You revealed it exceptionally well.
    https://www.waltcoexpress.com/
    pharmacy prescription
    canada pharmacy online
    prescription drug price comparison
    canada pharmaceuticals online

  14. Your comment is awaiting moderation.

    With thanks! Numerous advice.

    https://www.interlandchemie.com/
    online canadian pharmacies
    canadian viagra
    online drugstore
    canadian pharmacies

  15. Your comment is awaiting moderation.

    Regards, Numerous posts!

    https://www.interlandchemie.com/
    the canadian pharmacy
    canadian pharmacies
    canadian pharmacy meds
    canadianpharmacy

  16. Your comment is awaiting moderation.

    Regards, Helpful stuff.
    https://www.interlandchemie.com/
    prescription without a doctor’s prescription
    top rated canadian pharmacies online
    canada pharmacies online prescriptions
    canadian viagra

  17. Your comment is awaiting moderation.

    Helpful content. Cheers!
    https://www.interlandchemie.com/
    online rx pharmacy
    online pharmacies of canada
    canadian pharmacies shipping to usa
    online pharmacies canada

  18. Your comment is awaiting moderation.

    You’ve made your position quite clearly!!
    https://www.interlandchemie.com/
    canada pharmacies prescription drugs
    online pharmacies of canada
    online drugs
    london drugs canada

  19. Your comment is awaiting moderation.

    Many thanks, I like it!
    https://www.waltcoexpress.com/
    canadian pharmacy online
    canada pharmaceutical online ordering
    most reliable canadian pharmacies
    canadian pharmacies without an rx

  20. Your comment is awaiting moderation.

    Thanks a lot. I value it.
    https://www.visitwaushara.com/
    pain meds online without doctor prescription
    canadian pharmacies
    canadian viagra
    online pharmacies canada

  21. Your comment is awaiting moderation.

    Many thanks! Helpful stuff.
    https://www.lunarciel.com/
    canadian pharmacy meds
    canadian pharmacies online
    best online pharmacies no prescription
    canada pharmaceutical online ordering

  22. Your comment is awaiting moderation.

    Very good tips. Cheers.
    https://www.visitwaushara.com/
    canadian drug stores online
    canada online pharmacies
    the canadian pharmacy
    top rated canadian pharmacies online

  23. Your comment is awaiting moderation.

    Wonderful postings. Thanks a lot!
    https://www.waltcoexpress.com/
    prescription drug assistance
    northwest pharmacy
    us pharmacy no prior prescription
    canadian pharmacy

  24. Your comment is awaiting moderation.

    Many thanks! Great information.
    https://www.interlandchemie.com/
    canadian drug store
    canada pharmacy online
    online pharmacy usa
    aarp approved canadian online pharmacies

  25. Your comment is awaiting moderation.

    You have made your stand quite clearly!!
    https://www.interlandchemie.com/
    canada drug prices
    canadian online pharmacies
    prescription drugs without doctor approval
    canada drugs online

  26. Your comment is awaiting moderation.

    Valuable material. Appreciate it.
    https://www.lunarciel.com/
    canada pharmacy online
    canadian pharmacy
    canada pharmacies prescription drugs
    canada pharmacy online

  27. Your comment is awaiting moderation.

    Fine stuff. Kudos!
    https://www.interlandchemie.com/
    canadian pharmacy meds
    trust pharmacy canada
    no prescription online pharmacy
    global pharmacy canada

  28. Your comment is awaiting moderation.

    You actually said that terrifically.
    https://www.lunarciel.com/
    overseas pharmacy forum
    northwest pharmacy
    prescription drug assistance
    canada drugs

  29. Your comment is awaiting moderation.

    Great data. Thanks a lot!
    https://www.visitwaushara.com/
    best online pharmacies canada
    global pharmacy canada
    canadapharmacyonline.com
    north west pharmacy canada

  30. Your comment is awaiting moderation.

    You actually mentioned that really well!
    https://www.visitwaushara.com/
    best online pharmacies canada
    online pharmacies canada
    ed meds online
    canada pharmaceutical online ordering

  31. Your comment is awaiting moderation.

    You actually revealed this adequately!
    https://www.interlandchemie.com/
    mexican online pharmacies
    canada drug
    canadian pharmacy king
    global pharmacy canada

  32. Your comment is awaiting moderation.

    You said it perfectly..
    https://www.dunamisproductions.com/
    drugs from canada
    canadian pharmacies
    canada drugs
    northwestpharmacy

  33. Your comment is awaiting moderation.

    Factor nicely considered!!
    https://www.dunamisproductions.com/
    canadian pharmacies that ship to us
    london drugs canada
    pharmacy drug store
    canada drugs

  34. Your comment is awaiting moderation.

    With thanks! A good amount of information.

    https://www.waltcoexpress.com/
    costco pharmacy pricing
    north west pharmacy canada
    no prescription pharmacies
    global pharmacy canada

  35. Your comment is awaiting moderation.

    Thanks, Wonderful stuff!
    https://www.dunamisproductions.com/
    canadian pharmacies top best
    canadian pharmacy
    canadian pharma companies
    northwest pharmacy

  36. Your comment is awaiting moderation.

    Truly plenty of valuable info!
    https://www.dunamisproductions.com/
    canadian pharmacy king
    canadian viagra
    prescription prices comparison
    canada drugs

  37. Your comment is awaiting moderation.

    Incredible a good deal of wonderful information!
    https://www.dunamisproductions.com/
    prescription prices comparison
    online pharmacies canada
    pharmacy canada
    canadian pharmaceuticals online

  38. Your comment is awaiting moderation.

    Reliable stuff. Thanks a lot!
    https://www.dunamisproductions.com/
    canadapharmacyonline.com
    online pharmacies of canada
    canada pharmacies online pharmacy
    canadian drugs

  39. Your comment is awaiting moderation.

    Wonderful posts. Kudos.
    https://www.dunamisproductions.com/
    visit poster’s website
    canadian pharmacies without an rx
    pharmacy online mexico
    canadian viagra

  40. Your comment is awaiting moderation.

    Kudos. Plenty of info!

    https://www.waltcoexpress.com/
    canadian pharma companies
    northwest pharmacy
    drugs without prescription
    canada drugs online

  41. Your comment is awaiting moderation.

    Fine info. Kudos.
    https://www.interlandchemie.com/
    no prescription pharmacy
    canadian online pharmacies
    canadian pharmacies shipping to usa
    canada pharmacy online

  42. Your comment is awaiting moderation.

    Regards, I enjoy it.
    https://www.interlandchemie.com/
    canada pharmacies
    canada pharmaceutical online ordering
    price prescription drugs
    canadian drugs

  43. Your comment is awaiting moderation.

    Thanks a lot! Helpful stuff!
    https://www.dunamisproductions.com/
    prescription price comparison
    canadian pharmacies-24h
    online canadian pharmacies
    canada pharmacy

  44. Your comment is awaiting moderation.

    Position effectively applied.!
    https://www.visitwaushara.com/
    pharmacy cost comparison
    canadian pharmacies
    canada drug
    online pharmacies canada

  45. Your comment is awaiting moderation.

    You made your position pretty well!!
    https://www.lunarciel.com/
    canadian online pharmacy reviews
    canadian pharmacies-24h
    online drugstore
    canada drugs online

  46. Your comment is awaiting moderation.

    Perfectly spoken indeed! .
    https://www.lunarciel.com/
    canadian pharmacy online
    canada pharmacy online
    canadian pharmacy
    canadian pharmacies-24h

  47. Your comment is awaiting moderation.

    You stated this adequately!
    https://www.waltcoexpress.com/
    best online pharmacy
    canada drugs online
    drugs from canada
    canada pharmacy

  48. Your comment is awaiting moderation.

    Good facts, Thanks a lot!
    https://www.visitwaushara.com/
    no prescription pharmacies
    northwest pharmacy
    best online pharmacy
    top rated canadian pharmacies online

  49. Your comment is awaiting moderation.

    Wow a good deal of great material!
    https://www.lunarciel.com/
    mexican pharmacy online
    canada online pharmacies
    canadian pharmacy viagra
    trust pharmacy canada

  50. Your comment is awaiting moderation.

    Good stuff. Many thanks!
    https://www.dunamisproductions.com/
    safeway pharmacy
    canadian cialis
    prescription drugs without prior prescription
    top rated canadian pharmacies online

  51. Your comment is awaiting moderation.

    You stated this adequately!
    https://www.interlandchemie.com/
    northwest pharmacy canada
    north west pharmacy canada
    mail order pharmacies
    canadian pharmaceuticals online

  52. Your comment is awaiting moderation.

    Cheers! Plenty of forum posts.

    https://www.waltcoexpress.com/
    drugs without prescription
    northwest pharmacy
    canada pharmacy online
    canada online pharmacies

  53. Your comment is awaiting moderation.

    With thanks. A lot of info!

    https://www.dunamisproductions.com/
    canada pharmacy online reviews
    canadian pharmacies-24h
    discount pharmaceuticals
    northwest pharmacy

  54. Your comment is awaiting moderation.

    Kudos! Ample tips.

    https://www.waltcoexpress.com/
    canadian pharmacies that are legit
    canada pharmaceuticals online
    canadadrugs.com pharmacy
    top rated canadian pharmacies online

  55. Your comment is awaiting moderation.

    Incredible quite a lot of useful knowledge.
    https://www.dunamisproductions.com/
    pharmacy prices compare
    canadian cialis
    prescription drug price comparison
    aarp approved canadian online pharmacies

  56. Your comment is awaiting moderation.

    Appreciate it! A good amount of stuff!

    https://www.interlandchemie.com/
    mexican pharmacies shipping to usa
    canadian online pharmacies
    pharmacy drug store
    canada pharmaceuticals online

  57. Your comment is awaiting moderation.

    Fantastic posts. Appreciate it!
    https://www.lunarciel.com/
    pharmacy prescription
    northwest pharmacy
    buy prescription drugs from canada
    canadian pharmaceuticals online

  58. Your comment is awaiting moderation.

    Awesome facts. Regards.
    https://www.lunarciel.com/
    prescription drugs without prior prescription
    canada pharmaceuticals online
    legitimate canadian mail order pharmacies
    canada pharmaceuticals online

  59. Your comment is awaiting moderation.

    Whoa many of superb knowledge!
    https://www.lunarciel.com/
    canadian pharmacies without prescriptions
    canadian online pharmacies
    online discount pharmacy
    mexican pharmacies shipping to usa

  60. Your comment is awaiting moderation.

    Thanks, I value this!
    https://www.lunarciel.com/
    canadadrugs.com pharmacy
    canadian pharmacy
    compare prescription prices
    canadian pharmacies online

  61. Your comment is awaiting moderation.

    Well voiced really. .
    https://www.interlandchemie.com/
    pharmacies in canada
    canadian pharmacy online
    online pharmacies no prescription
    canadian online pharmacies

  62. Your comment is awaiting moderation.

    Wow all kinds of helpful data.
    https://www.interlandchemie.com/
    cheap prescription drugs online
    canadian pharmacy
    canadian pharmacy no prescription needed
    online pharmacies of canada

  63. Your comment is awaiting moderation.

    Appreciate it. Lots of content!

    https://www.dunamisproductions.com/
    drug stores near me
    canadian pharmacies
    prescription drug
    trust pharmacy canada

  64. Your comment is awaiting moderation.

    Kudos, A good amount of material!

    https://www.waltcoexpress.com/
    online pharmacies
    canadian pharmacies online
    board of pharmacy
    canadian cialis

  65. Your comment is awaiting moderation.

    Nicely put, Cheers!
    https://www.waltcoexpress.com/
    no 1 canadian pharcharmy online
    canadianpharmacy
    canadian prescription drugstore
    canada pharmaceuticals online

  66. Your comment is awaiting moderation.

    Cheers! Quite a lot of information.

    http://canadianpharmaciescubarx.com/
    best canadian pharmacies
    north west pharmacy canada
    canadian prescription drugs
    north west pharmacy canada

  67. Your comment is awaiting moderation.

    Wonderful data. With thanks!
    http://canadianpharmacyntx.com/
    mexican pharmacies shipping to usa
    northwest pharmacy
    prescription drug cost
    canadian pharmacies without an rx

  68. Your comment is awaiting moderation.

    Beneficial knowledge. With thanks.
    http://canadianpharmacymim.com/
    canada drugs online
    canadian cialis
    safeway pharmacy
    online pharmacies of canada

  69. Your comment is awaiting moderation.

    Truly a lot of fantastic material.
    http://canadianpharmaciescubarx.com/
    prescription drug assistance
    canadian online pharmacy
    drugs from canada
    canadianpharmacy

  70. Your comment is awaiting moderation.

    You expressed it superbly!
    http://canadianonlinepharmacynnm.com/
    canadian pharma companies
    northwest pharmacy
    canadian online pharmacy reviews
    london drugs canada

  71. Your comment is awaiting moderation.

    Truly tons of excellent information.
    http://canadianpharmacymim.com/
    canada pharmacies
    canadian pharmacies that ship to us
    canada pharmacy online
    london drugs canada

  72. Your comment is awaiting moderation.

    Many thanks, I like it.
    https://nicktambone.com/
    canada meds
    canada pharmacy online
    internet pharmacy
    canadian drugs

  73. Your comment is awaiting moderation.

    Thanks. I value this!
    http://canadianpharmaciesnnm.com/
    reputable canadian mail order pharmacies
    london drugs canada
    mexican pharmacies online
    online pharmacies of canada

  74. Your comment is awaiting moderation.

    You said that exceptionally well!
    http://talahicc.com/
    online pharmacy canada
    canadian pharmacies-24h
    drugs for sale
    northwestpharmacy

Leave a Reply

Your email address will not be published. Required fields are marked *