Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here you go, I provide an example for .cs and .vb but shouldn't be hard for you to adjust it to your other file type needs: <strong><em>Edited to recursively add header to sub-folders</em></strong></p> <pre><code>Sub IterateFiles() Dim solution As Solution = DTE.Solution For Each prj As Project In solution.Projects IterateProjectFiles(prj.ProjectItems) Next End Sub Private Sub IterateProjectFiles(ByVal prjItms As ProjectItems) For Each file As ProjectItem In prjItms If file.SubProject IsNot Nothing Then AddHeaderToItem(file) IterateProjectFiles(file.ProjectItems) ElseIf file.ProjectItems IsNot Nothing AndAlso file.ProjectItems.Count &gt; 0 Then AddHeaderToItem(file) IterateProjectFiles(file.ProjectItems) Else AddHeaderToItem(file) End If Next End Sub Private Sub AddHeaderToItem(ByVal file As ProjectItem) DTE.ExecuteCommand("View.SolutionExplorer") If file.Name.EndsWith(".cs") OrElse file.Name.EndsWith(".vb") Then file.Open() file.Document.Activate() AddHeader() file.Document.Save() file.Document.Close() End If End Sub Private Sub AddHeader() Dim cmtHeader As String = "{0} First Line" Dim cmtCopyright As String = "{0} Copyright 2008" Dim cmtFooter As String = "{0} Footer Line" Dim cmt As String Select Case DTE.ActiveDocument.Language Case "CSharp" cmt = "//" Case "Basic" cmt = "'" End Select DTE.UndoContext.Open("Header Comment") Dim ts As TextSelection = CType(DTE.ActiveDocument.Selection, TextSelection) ts.StartOfDocument() ts.Text = String.Format(cmtHeader, cmt) ts.NewLine() ts.Text = String.Format(cmtCopyright, cmt) ts.NewLine() ts.Text = String.Format(cmtFooter, cmt) ts.NewLine() DTE.UndoContext.Close() End Sub </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload