VS利用宏快速找到页面

下面的宏用于将剪贴板里面的url指定的文件在vs.net中打开以便编辑,目的是提高打开文件的速度
比如:你在ie中运行一个系统时,某一个页面有错,这个时候你需要修改这个页面,那么你只需要复制该页面的url,然后到vs.net中使用一个运行宏的快捷键就可以打开修改该页面了(最好事先打开了解决方案,这样该文件是作为解决方案中的一个文件打开的,而不是一个单独的与项目无关的文件)。如果不使用宏你将不得不打开解决方案资源管理器,一层一层的展开树,然后找到要修改的文件

Imports EnvDTE
Imports System.Diagnostics
Imports System.Windows.Forms
Imports System.Threading

Public Module RecordingModule
    Dim ClipString As String
    Sub TemporaryMacro()
        
' // take whatever is on the clipboard and save it to an xml file
         ' // intended for cut & paste from QueryAnalyzer
        Dim ClipBoardThread As System.Threading.Thread  =  New System.Threading.Thread(AddressOf getClipString_core)
        With ClipBoardThread
            .ApartmentState 
=  ApartmentState.STA
            .IsBackground 
=  True
            .Start()
            
' -- Wait for copy to happen
            .Join()
        End With
        ClipBoardThread 
=  Nothing
        If ClipString 
<>   ""  Then
            
' 虚拟目录名()
            Dim VirtualName  =   " kxframework "
            Dim pos 
=  InStr(LCase(ClipString),  " / "   &  VirtualName  &   " / " )
            If (pos 
=   0 ) Then
                pos 
=  InStr(LCase(ClipString),  " " & VirtualName &  " " )
            End If
            If (pos 
<>   0 ) Then
                ClipString 
=  Right(ClipString, Len(ClipString)  -  pos  -  Len( " " & VirtualName &  " " ) + 1)
            End If
            pos 
=  InStr(ClipString,  " ? " )
            If (pos 
<>   0 ) Then
                ClipString 
=  Left(ClipString, pos  -   1 )
            End If
            
' 组合成正确的物理路径
            ClipString  =   " E:科信施工项目成本管理系统" & VirtualName &  " "  & ClipString
            ClipString  =  Replace(ClipString,  " / " " ")
            If System.IO.File.Exists(ClipString) Then
                DTE.ItemOperations.OpenFile(ClipString)
            Else
                MessageBox.Show(
" 文件( "   &  ClipString  &   " )未找到! " )
            End If
        End If
    End Sub
    Sub getClipString_core()
        ClipString 
=  Clipboard.GetDataObject().GetData(System.Windows.Forms.DataFormats.StringFormat)
    End Sub
End Module
 
上面的方法只能确定一个WEB工程,所以我改进了一下,运行时出错,会有一个完整的错误页面地址,只要COPY那个完整的地址,然后调用下面的宏即可:
Imports EnvDTE
Imports System.Diagnostics
Imports System.Windows.Forms
Imports System.Threading

Public Module QuickFindPage
    Dim ClipString As String
    Sub QuickFindPage()
        '// take whatever is on the clipboard and save it to an xml file
        '// intended for cut & paste from QueryAnalyzer
        Dim ClipBoardThread As System.Threading.Thread = New System.Threading.Thread(AddressOf getClipString_core)
        With ClipBoardThread
            .ApartmentState = ApartmentState.STA
            .IsBackground = True
            .Start()
            '-- Wait for copy to happen
            .Join()
        End With
        ClipBoardThread = Nothing
        ClipString = Replace(ClipString, "/", "/")
        If ClipString <> "" Then
            If System.IO.File.Exists(ClipString) Then
                DTE.ItemOperations.OpenFile(ClipString)
            Else
                Dim posControl = InStr(ClipString, ".ascx")
                If (posControl <> 0) Then
                    Dim ClipString1 = "D:/Rhombus2/2-Software Development/4-Software Implementation/2-Source Files/Source DEV/RhombusSolution/Rhombus2/CO/Control/" & ClipString
                    Dim ClipString2 = "D:/Rhombus2/2-Software Development/4-Software Implementation/2-Source Files/Source DEV/RhombusSolution/Rhombus2/PO/Control/" & ClipString
                    Dim ClipString3 = "D:/Rhombus2/2-Software Development/4-Software Implementation/2-Source Files/Source DEV/RhombusSolution/Rhombus2/IV/Control/" & ClipString
                    Dim ClipString4 = "D:/Rhombus2/2-Software Development/4-Software Implementation/2-Source Files/Source DEV/RhombusSolution/Rhombus2/IN/Control/" & ClipString
                    Dim ClipString5 = "D:/Rhombus2/2-Software Development/4-Software Implementation/2-Source Files/Source DEV/RhombusSolution/Rhombus2/SH/Control/" & ClipString
                    If System.IO.File.Exists(ClipString1) Then
                        DTE.ItemOperations.OpenFile(ClipString1)
                    ElseIf System.IO.File.Exists(ClipString2) Then
                        DTE.ItemOperations.OpenFile(ClipString2)
                    ElseIf System.IO.File.Exists(ClipString3) Then
                        DTE.ItemOperations.OpenFile(ClipString3)
                    ElseIf System.IO.File.Exists(ClipString4) Then
                        DTE.ItemOperations.OpenFile(ClipString4)
                    ElseIf System.IO.File.Exists(ClipString5) Then
                        DTE.ItemOperations.OpenFile(ClipString5)
                    Else
                        MessageBox.Show("Can not find the file !")
                    End If
                Else
                    '虚拟目录名()
                    Dim VirtualName = "Rhombus2_YEA"
                    Dim pos = InStr(ClipString, "/" & VirtualName & "/")
                    If (pos <> 0) Then
                        ClipString = Right(ClipString, Len(ClipString) - pos - Len("/" & VirtualName & "/") + 1)
                    End If
                    pos = InStr(ClipString, "?")
                    If (pos <> 0) Then
                        ClipString = Left(ClipString, pos - 1)
                    End If
                    '组合成正确的物理路径
                    ClipString = "D:/Rhombus2/2-Software Development/4-Software Implementation/2-Source Files/Source DEV/RhombusSolution/Rhombus2/" & ClipString
                    If System.IO.File.Exists(ClipString) Then
                        DTE.ItemOperations.OpenFile(ClipString)
                    Else
                        MessageBox.Show("Can not find the file !")
                    End If
                End If
            End If
        End If
    End Sub
    Sub getClipString_core()
        ClipString = Clipboard.GetDataObject().GetData(System.Windows.Forms.DataFormats.StringFormat)
    End Sub
End Module


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值