I’ve been using a Visual Studio macro to switch between markup and code-behind for years now. I’ve forgotten where I originally obtained the code for this Visual Studio macro. If you search around you can find incarnations of it floating around the web. I created a really short tutorial explaining how to setup the macro at the end of this post.
Public Sub Switch()
Dim FileName As String
If (DTE.ActiveWindow.Document.FullName.ToLower().EndsWith(".cs")) Then
' swith from .aspx.cs to .aspx
FileName = DTE.ActiveWindow.Document.FullName.ToLower().Replace(".cs", "")
If System.IO.File.Exists(FileName) Then
DTE.ItemOperations.OpenFile(FileName)
End If
ElseIf (DTE.ActiveWindow.Document.FullName.ToLower().EndsWith(".aspx")) Then
' swith from .aspx to .aspx.cs
FileName = DTE.ActiveWindow.Document.FullName.ToLower().Replace(".aspx", ".aspx.cs")
If System.IO.File.Exists(FileName) Then
DTE.ItemOperations.OpenFile(FileName)
End If
ElseIf (DTE.ActiveWindow.Document.FullName.ToLower().EndsWith(".ascx")) Then
FileName = DTE.ActiveWindow.Document.FullName.ToLower().Replace(".ascx", ".ascx.cs")
If System.IO.File.Exists(FileName) Then
DTE.ItemOperations.OpenFile(FileName)
End If
ElseIf (DTE.ActiveWindow.Document.FullName.ToLower().EndsWith(".master")) Then
FileName = DTE.ActiveWindow.Document.FullName.ToLower().Replace(".master", ".master.cs")
If System.IO.File.Exists(FileName) Then
DTE.ItemOperations.OpenFile(FileName)
End If
End If
End Sub
I created a short tutorial to show how to setup the macro in Visual Studio.
I hope this helps! Enjoy :-D
Next entry: My review of Dan Brown’s The Lost Symbol
Previous Entry: dasBlog macros used by TheThoughtfulCoder.com
Latest entries:
Create absolute URLs using ASP.NET MVC
Comments
Correct me if I'm wrong, but I'm pretty sure the built in F7 only switches from markup to code behind. I just tried it, and it doesn't go from code behind to markup. This macro makes it so you can toggle back and forth very quickly. Of course I might be missing the boat :-)
My Links
Tags
Follow me
About
Powered by FoxBlog
Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.
© Copyright 2011, Nathan Fox
F7 or Alt+F7, man :)
Belorus - September 3, 2010