Thursday, August 12, 2010

Visual Studio 2010 Macro - UnEscape text and change &gt; &lt; to <>

This is a little macro which will unescape &gt; and %lt; and convert them to the correct mode when editing XML in VS2010

1 Imports System
2 Imports EnvDTE
3 Imports EnvDTE80
4 Imports EnvDTE90
5 Imports System.Diagnostics
6
7 Public Module UnEscapeGTLT
8 Sub UnEscapeGTLT()
9
10 DTE.ExecuteCommand("Edit.Replace")
11
12 DTE.ActiveDocument.Activate()
13 DTE.ExecuteCommand("Edit.Replace")
14 DTE.Find.FindWhat = "&gt;"
15 DTE.Find.ReplaceWith = ">"
16 DTE.Find.Target = vsFindTarget.vsFindTargetCurrentDocument
17 DTE.Find.MatchCase = False
18 DTE.Find.MatchWholeWord = False
19 DTE.Find.MatchInHiddenText = False
20 DTE.Find.PatternSyntax = vsFindPatternSyntax.vsFindPatternSyntaxLiteral
21 DTE.Find.ResultsLocation = vsFindResultsLocation.vsFindResultsNone
22 DTE.Find.Action = vsFindAction.vsFindActionReplaceAll
23 If (DTE.Find.Execute() = vsFindResult.vsFindResultNotFound) Then
24 Throw New System.Exception("vsFindResultNotFound")
25 End If
26 DTE.Windows.Item("{CF2DDC32-8CAD-11D2-9302-005345000000}").Activate() 'Find and Replace
27 DTE.Find.FindWhat = "&lt;"
28 DTE.Find.ReplaceWith = "<"
29 DTE.ActiveDocument.Activate()
30 DTE.Find.Target = vsFindTarget.vsFindTargetCurrentDocument
31 DTE.Find.MatchCase = False
32 DTE.Find.MatchWholeWord = False
33 DTE.Find.MatchInHiddenText = False
34 DTE.Find.PatternSyntax = vsFindPatternSyntax.vsFindPatternSyntaxLiteral
35 DTE.Find.ResultsLocation = vsFindResultsLocation.vsFindResultsNone
36 DTE.Find.Action = vsFindAction.vsFindActionReplaceAll
37 If (DTE.Find.Execute() = vsFindResult.vsFindResultNotFound) Then
38 Throw New System.Exception("vsFindResultNotFound")
39 End If
40 DTE.Windows.Item("{CF2DDC32-8CAD-11D2-9302-005345000000}").Close()
41 DTE.ExecuteCommand("Edit.FormatDocument")
42 End Sub
43
44 End Module
45

Wednesday, August 11, 2010

Code Snippit : Extension Method to Set date to begin or end of day

Imports System.Runtime.CompilerServices

Module DateExtension
<Extension()>
Public Function StartOfDay(ByVal d1 As Date) As Date
Return Date.Parse(d1.ToString("dd/MM/yyyy 00:00:00"))
End Function
<Extension()>
Public Function EndOfDay(ByVal d1 As Date) As Date
Return Date.Parse(d1.ToString("dd/MM/yyyy 23:59:59"))
End Function
End Module

DOS Command for Deleting Subfolders and Files

 

The post is just a reminder of script for delete all subfolders and files

 

FOR /D %%p IN ("C:\Users\_IRIS OutputService\AppData\Local\Temp\*.*") DO rmdir "%%p" /s /q