ASP.NET Markup Go To Definition and Snippets

I don’t know if this is something new in VS or if it’s because I have the power tools installed, but I just realized that I can pick “Go to Definition” on an asp.net object in my code behind, like a label, or an asp.net checkbox, and instead of taking me to the vb definition of the control, it takes me to the place where the object is defined in the ASPX markup.   

And, in vs2010 if you auto complete with pressing tab 2 times when adding aspx markup items it will auto complete the entire element, not just the little bit you are typing.

 

So for example, if you type “<asp:But” and press tab you get:

 

<asp:Button

 

But if you tab again you get:

 

<asp:Button Text=”text” runat=”server” />

 

There are snippets included that are named things like “textbox” and “button”, so if you type “<bu” or “<hyp” and hit tab 2 times you get:

<asp:Button Text="text" runat="server" />

Or

<asp:HyperLink NavigateUrl="navigateurl" runat="server" />

 

Repoint Access linked tables to different connection string

I’ve been looking for a way to do this for a project I’m working on.

The access app has linked tables that are on a SQL server, but it doesn’t use a DSN.  Instead the connection string is somewhere unknown to the user and so repointing it (like user server1 instead of server2, or db1 instead of db2) was a major pain point.

Finally I found some code that I can use to change it.  I changed some names, but you get the idea. 

Private Sub Detail_DblClick(ByVal Cancel As Integer)
     Dim db As Database, source As String, path As String
     Dim dbsource As String, i As Integer, j As Integer

     db = DBEngine.Workspaces(0).Databases(0)

     For i = 0 To db.TableDefs.count - 1
         If db.TableDefs(i).Connect <> " " Then
             If Right(db.TableDefs(i).Connect, 15) = "DbNameHere12345" Then
                 db.TableDefs(i).Connect = db.TableDefs(i).Connect & "Updated"
                 db.TableDefs(i).RefreshLink()
             End If

         End If
     Next
 End Sub

 

Convert Spaces To Tabs For A Visual Studio Solution or Project

I recently installed some VS.Net power tools, and 1 of the tools is something that tells you when you have a file with mixed tabs and spaces, giving you the chance to convert from one to another.

I decided to stick with Tabs (I know that spaces v. tabs is a religious war for many, but I won’t go into it).  The problem is that this only happens on a file by file basis.  Furthermore, when you change the whitespace, your source controls sees that lots and lots of lines in your file have changed, making it hard to see the 1 or 2 lines that ACTUALLY changed.

I didn’t find a single utility out there for converting spaces to tabs, so after some poking around I’ve come up with a workaround that does the trick, even if it is a bit hackish.

I created a Find/Replace regular expression that will find leading groups of 4 spaces and replace them with tabs.  The problem is: you have to run it recursively.  So if you have a spot in your code with 10 tabs of indentation, you’ll need to run the find/replace 10 times in a row, which each iteration converting 1 of the groups of 4 spaces to a tab.

Each time you run the Find/Replace the count will get smaller and smaller, until finally: 0.

The basic pattern you search for is:

^{(t)*}([ ]^4)

and you replace with:

1t

In this example, the ^4 means that I’m treating 4 spaces as a tab.  Change the number if you want to have 2 spaces = a tab or whatever.

Another thing you can do to make it run faster on a large project is to first try to replace large sections of spaces before replaces 4 spaces at a time.  For example, the following stuff will search for 20 spaces and replace with 5 tabs.

You search for:

^{(t)*}([ ]^20)

and you replace with:

1ttttt

This way, if you have 1 spot in your code with 60 spaces, you won’t have to run the replace 15 times.