| 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.
- Open Microsoft ASP.NET Web Matrix. You will see the New
File dialog box appear.
- Select (General) from the Templates pane.
- Select the ASP.NET Page template.
- Type a file path in the Location box.
- Type myFirstSnippet.aspx in the Filename box.
- Select Visual Basic in the Language drop-down box.
- Click OK. The myFirstSnippet.aspx file will open in
Design view.
- From the Web Controls tab in the Toolbox, drag a
Label control onto the ASP.NET page.
- Select the HTML tab.
- Select the My Snippets tab in the Toolbox.
- From the HTML tab, select the code that renders the Label
control.
- Drag the selected code onto the My Snippets tab in the
Toolbox.
- 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.
- Right-click on the code snippet in the My Snippets tab.
- Select Rename.
- Type MyFirstSnippet.
- Right-click on MyFirstSnippet in the My Snippets tab.
- Select Exports Snippets to a file.
- You will see step one of the Export Snippets Wizard appear; it
is called the Select Snippets dialog box.
- Select the check box next to the MyFirstSnippet item in the
snippets pane.
- Click Next.
- You will see step two of the Export Snippets Wizard appear; it
is called the Select Export File dialog box.
- Type a file path in the box.
- Click Finsh.
- 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.
- 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.
- 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>
- Right-click on MyFirstSnippet in the My Snippets tab.
- Select Remove.
- Right-click in the My Snippets tab in the Toolbox.
- Select Import Snippets to a file.
- You will see step one of the Import Snippets Wizard appear; it
is called the Select Import File dialog box.
- Type in or browse to the MyFirstSnippet.snippets file you
exported earlier in this walkthrough.
- Click Next.
- You will see step two of the Import Snippets Wizard appear; it
is called the Select Snippets dialog box.
- Select the check box next to the MyFirstSnippet item in the
snippets pane.
- Click Finsh.
- ASP.NET Web Matrix will import the selected snippet from the specified
file and display it as an item in the My Snippets tab.
- Select the HTML tab.
- Delete the code that renders the Label control.
- Select the MyFirstSnippet item in the My Snippets tab.
- Drag the selected snippet onto the HTML tab. Place the snippet
in the same position as the deleted code that renders the Label
control.
Next Step >> |