locked
Help with macro in VS2008 to replace/add code in WebApplications RRS feed

  • Question

  • Hello.

    I'm switching now from PHP to ASP.NET and, while I'm not completely lost with Visual Studio, I can't really find myself writing (or even recording) proper macros, so I come here for help.

    The macro I'm thinking is somewhat simple: I want to be able to replace all (transitional by default) DTDs in all .aspx documents with xhtml 1.0 strict DTDs, plus I would like to add

    <xhtmlConformance mode="Strict" />

     

    inside the < system.web > element in the web.config document if not already added .

    I've tried recording it, but in the end it became very bloated, and not 100% functional.

    I know I could just install the xhtml 1.1 VS templates from codeplex , or even create my own with the desired changes, but I rather stick with the default templates and just edit what I need on the fly - the DTDs and enable "real" strict validation while developing (by editing web.config).

    Anyone with enough macro knowledge able to help a fellow out? Thanks in advance.

    [Please forgive the - possibly - broken English. It is not my primary language.]

     

    EDIT

    For clarification, the DTD substitution would be like this:

    REPLACE

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    WITH

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

    • Edited by Mike Valeriano Tuesday, April 6, 2010 11:28 PM Clarification
    Tuesday, April 6, 2010 11:18 PM

Answers

  • Hello,

    You could not use Record to create this macro.

    We could write the Macro easily, the Automation has a replace a TextDocument.ReplacePattern Method which enable you to replace the text in current Active text document.

    Just like

        Sub ReplaceTxt()

            Dim txtDoc As TextDocument = CType(DTE.ActiveDocument.Object, TextDocument)

            Dim originalStr As String = "<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Transitional//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"">"

            Dim ReplacedStr As String = "<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Strict//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"">"

            txtDoc.ReplacePattern(originalStr, ReplacedStr)

            DTE.ExecuteCommand("File.SaveAll",String.Empty)

        End Sub

    If you run this Macro, the text will be replaced.

    You mentioned you want to insert <xhtmlConformance mode="Strict" /> to your Web.config file.
    The automation has provide you the solution path of your solution(DTE.Solution .FullName), this enable you to find your Web.Config path easily, you could insert this element to Web.config file easily by using XmlDocument class.
    Thanks
    Chao
    Thursday, April 8, 2010 8:15 AM

All replies

  • Hello,

    You could not use Record to create this macro.

    We could write the Macro easily, the Automation has a replace a TextDocument.ReplacePattern Method which enable you to replace the text in current Active text document.

    Just like

        Sub ReplaceTxt()

            Dim txtDoc As TextDocument = CType(DTE.ActiveDocument.Object, TextDocument)

            Dim originalStr As String = "<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Transitional//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"">"

            Dim ReplacedStr As String = "<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Strict//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"">"

            txtDoc.ReplacePattern(originalStr, ReplacedStr)

            DTE.ExecuteCommand("File.SaveAll",String.Empty)

        End Sub

    If you run this Macro, the text will be replaced.

    You mentioned you want to insert <xhtmlConformance mode="Strict" /> to your Web.config file.
    The automation has provide you the solution path of your solution(DTE.Solution .FullName), this enable you to find your Web.Config path easily, you could insert this element to Web.config file easily by using XmlDocument class.
    Thanks
    Chao
    Thursday, April 8, 2010 8:15 AM
  • Hello,

    You could not use Record to create this macro.

    We could write the Macro easily, the Automation has a replace a TextDocument.ReplacePattern Method which enable you to replace the text in current Active text document.

    Just like

        Sub ReplaceTxt()

            Dim txtDoc As TextDocument = CType(DTE.ActiveDocument.Object, TextDocument)

            Dim originalStr As String = "<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Transitional//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"">"

            Dim ReplacedStr As String = "<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Strict//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"">"

            txtDoc.ReplacePattern(originalStr, ReplacedStr)

            DTE.ExecuteCommand("File.SaveAll",String.Empty)

        End Sub

    If you run this Macro, the text will be replaced.

    You mentioned you want to insert <xhtmlConformance mode="Strict" /> to your Web.config file.
    The automation has provide you the solution path of your solution(DTE.Solution .FullName), this enable you to find your Web.Config path easily, you could insert this element to Web.config file easily by using XmlDocument class.
    Thanks
    Chao
    Thursday, April 8, 2010 8:15 AM
  • Perfect! :) Many thanks!
    Thursday, April 8, 2010 8:17 AM