Thursday, September 22, 2016

Visual Studio Code Snippet Manager

Hi in this blog i am going to show how to create a code snippets for Visual Studio from scratch.The visual studio code code snippets make you work more easy and you don't have to type same code again and again.

This is code snippet for inserting Connectionstring:



<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>Connectionstring</Title>
<Shortcut>sqlconn</Shortcut>
<Description>Code snippet for Connectinstring</Description>
<Author>Author Name</Author>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
<SnippetType>SurroundsWith</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Code Language="csharp"><![CDATA[SqlConnection conn = new SqlConnection("Data Source=<Datasource here>;Initial Catalog=<Database Name>;Integrated Security=SSPI");]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>


Title Tag: Give your code snippet name between title tag.
Shortcut: Give the name of the shortcut that you use to insert your code snippet.

And then place your code snippet between CData[[ Code snippet here  ]].

How to use Visual Studio code snippets?

Copy paste the above code in notepad and save it as with an extension ".snippet".Then go to Tools -> Code Snippet Manager by select you language from the dropdown list.For this post i am selecting visual c#. Then click Import and select the folder in which your code snippet is saved. Then click ok. 



Now type the shortcut you assigned for you post and press "Tab" twice.you code will inserted.Or else Press "Ctrl+K" "Ctrl+s" intellisense will show list of snippets available in your system.Then select the snippet you want and then press Enter.

Download the code snippet for here.




No comments:

Post a Comment