ASP.NET Logo Back to WebMatrix Home

 
Help & Community
My Snippets
My Snippets provides you the ability to import code snippets that you can drag-and-drop into your file or create your own snippets and export them to an XML File that other developers can use to import into their applications.

In this walkthrough, you will add a new code snippet, export a code snippet to a file, and import a code snippet from a file.

  1. Open Microsoft ASP.NET Web Matrix.  You will see the New File dialog box appear.
  2. Select (General) from the Templates pane.
  3. Select the ASP.NET Page template.
  4. Type a file path in the Location box.
  5. Type myFirstSnippet.aspx in the Filename box.
  6. Select Visual Basic in the Language drop-down box.
  7. Click OK. The myFirstSnippet.aspx file will open in Design view. 

    New File Dialog

  8. From the Web Controls tab in the Toolbox, drag a Label control onto the ASP.NET page.

     
  9. Select the HTML tab.

     
  10. Select the My Snippets tab in the Toolbox

    My Snippets Tab

  11. From the HTML tab, select the code that renders the Label control.

     
  12. Drag the selected code onto the My Snippets tab in the Toolbox

    Drag Code To My Snippets

  13. You will see a new code snippet item appear in the My Snippets tab.

    Note The amount of visible snippet code in the My Snippets tab is dependent on the width of the Toolbox

    New Snippet Item

     

  14. Right-click on the code snippet in the My Snippets tab.

     
  15. Select Rename.

     
  16. Type MyFirstSnippet.

     
  17. Right-click on MyFirstSnippet in the My Snippets tab.

     
  18. Select Exports Snippets to a file

    Export Snippet

  19. You will see step one of the Export Snippets Wizard appear; it is called the Select Snippets dialog box.

     
  20. Select the check box next to the MyFirstSnippet item in the snippets pane.

     
  21. Click Next

    Select Export Snippet

  22. You will see step two of the Export Snippets Wizard appear; it is called the Select Export File dialog box.

     
  23. Type a file path in the box.

     
  24. Click Finsh

    Export Snippet File

  25. ASP.NET Web Matrix will export the selected snippet to the specified file.

     

    Note The file extenstion for an exported code snippet file is snippets.

     

  26. Browse to the file in the Workspace window open it.

     

    Important When using Windows Explorer to open a snippets file, the extenstion may not be associated with a program. Microsoft Windows cannot open a file without a program assocaition. If necessary, double-click on the file in Windows Explorer and Microsoft Windows will prompt you to make an association.

     

  27. You will see the code snippets file has an XML structure:

     

    <?xml version='1.0' encoding='UTF-8'?>
    <Snippets>
        <Snippet name="MyFirstSnippet">
            <asp:Label id="Label1" runat="server">Label</asp:Label>
        </Snippet>
    </Snippets>
    

     

  28. Right-click on MyFirstSnippet in the My Snippets tab.

     
  29. Select Remove.

     
  30. Right-click in the My Snippets tab in the Toolbox.

     
  31. Select Import Snippets to a file

    Import Snippet

  32. You will see step one of the Import Snippets Wizard appear; it is called the Select Import File dialog box.

     
  33. Type in or browse to the MyFirstSnippet.snippets file you exported earlier in this walkthrough.

     
  34. Click Next

    Select Import Snippet File

  35. You will see step two of the Import Snippets Wizard appear; it is called the Select Snippets dialog box.

     
  36. Select the check box next to the MyFirstSnippet item in the snippets pane.

     
  37. Click Finsh

    Imported Snippet Item

  38. ASP.NET Web Matrix will import the selected snippet from the specified file and display it as an item in the My Snippets tab.

     
  39. Select the HTML tab.

     
  40. Delete the code that renders the Label control.

     
  41. Select the MyFirstSnippet item in the My Snippets tab.

     
  42. Drag the selected snippet onto the HTML tab. Place the snippet in the same position as the deleted code that renders the Label control. 

    Drag Snippet To Page

Next Step >>