Skip to content

Instantly share code, notes, and snippets.

@blachniet
Created April 7, 2012 19:26
Show Gist options
  • Save blachniet/2331536 to your computer and use it in GitHub Desktop.
Save blachniet/2331536 to your computer and use it in GitHub Desktop.
VS Snippets
Snippets for Visual Studio
============================================
To Add a Code Snippet to Visual Studio
1. You can add your own snippets to your Visual Studio installation by using the Code Snippets Manager. Open the Code Snippets Manager (Tools/Code Snippets Manager).
2. Click the Import button.
3. Go to the location where you saved the code snippet in the previous procedure, select it, and click Open.
4. The Import Code Snippet dialog opens, asking you to choose where to add the snippet from the choices in the right pane. One of the choices should be My Code Snippets. Select it and click Finish, then OK.
5. The snippet is copied to the following location:
%USERPROFILE%\Documents\Visual Studio Dev11\Code Snippets\Visual Basic\My Code Snippets
6. Test your snippet by opening a Visual Basic project and opening a code file. In the file click Insert Snippet on the context menu, then My Code Snippets. You should see a snippet named My Visual Basic Code Snippet. Double-click it.
============================================
<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<_locDefinition xmlns="urn:locstudio">
<_locDefault _loc="locNone" />
<_locTag _loc="locData">Title</_locTag>
<_locTag _loc="locData">Description</_locTag>
<_locTag _loc="locData">Author</_locTag>
<_locTag _loc="locData">ToolTip</_locTag>
</_locDefinition>
<CodeSnippet Format="1.0.0">
<Header>
<Title>Create Table If Not Exists</Title>
<Shortcut></Shortcut>
<Description>Creates a table if it doesn't already exist.</Description>
<Author>Brian Lachniet</Author>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>SchemaName</ID>
<ToolTip>Name of the schema</ToolTip>
<Default>dbo</Default>
</Literal>
<Literal>
<ID>Tablename</ID>
<ToolTip>Name of the table</ToolTip>
<Default>Sample_Table</Default>
</Literal>
<Literal>
<ID>column1</ID>
<ToolTip>Name of the column</ToolTip>
<Default>column_1</Default>
</Literal>
<Literal>
<ID>datatype1</ID>
<ToolTip>Data type of the column</ToolTip>
<Default>int NOT NULL</Default>
</Literal>
<Literal>
<ID>column2</ID>
<ToolTip>Name of the column</ToolTip>
<Default>column_2</Default>
</Literal>
<Literal>
<ID>datatype2</ID>
<ToolTip>Data type of the column</ToolTip>
<Default>int NULL</Default>
</Literal>
</Declarations>
<Code Language="SQL_SSDT">
<![CDATA[IF NOT EXISTS (SELECT * FROM sys.tables WHERE name='$Tablename$')
BEGIN
CREATE TABLE $SchemaName$.$Tablename$
(
$column1$ $datatype1$,
$column2$ $datatype2$
);
END$end$]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
<CodeSnippet Format="1.1.0" xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<Header>
<Title>jQuery AJAX</Title>
<Author>Brian Lachniet</Author>
<Shortcut>jquery_ajax</Shortcut>
<Description>Code snippet for a jQuery ajax call.</Description>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>type</ID>
<ToolTip>The type of ajax call ('get', 'post')</ToolTip>
<Default>post</Default>
</Literal>
<Literal>
<ID>url</ID>
<ToolTip>The url for the ajax call to target. You can also use Razor syntax here: '@Url.Action("AddUser")'</ToolTip>
<Default>http://google.com</Default>
</Literal>
<Literal>
<ID>data</ID>
<ToolTip>The data to pass in the body of the request. This can be json, xml, or something else.</ToolTip>
<Default>jsonObject</Default>
</Literal>
<Literal>
<ID>data-type</ID>
<ToolTip>The type of data being passed in the body of the request.</ToolTip>
<Default>application/json</Default>
</Literal>
</Declarations>
<Code Language="JavaScript">
<![CDATA[$$.ajax({
type: '$type$',
url: '$url$',
data: $data$,
contentType: '$data-type$',
complete: function (data)
{
// Handle a completed request here.
},
error: function(data)
{
// Handle a failed request here.
}
});]]>
</Code>
</Snippet>
</CodeSnippet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment