Articles → .NET → Adding Your Own Code Snippet In Visual Studio 2008

Adding Your Own Code Snippet In Visual Studio 2008








Creation Of Code Snippet






<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
	<CodeSnippet Format="1.0.0"></CodeSnippet>
</CodeSnippets>








<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
	<CodeSnippet Format="1.0.0">
		<Header>
			<Title>MyCode</Title>
		</Header>
	</CodeSnippet>
</CodeSnippets>






public DataSet GetResultSet(string query) {
	DataSet resultSet = new DataSet();
	using(OleDbConnection connection = new OleDbConnection("")) {
		connection.Open();
		using(OleDbDataAdapter adapter = new OleDbDataAdapter(query, connection)) {
			adapter.Fill(resultSet);
		}
	}
	return resultSet;
}




<Snippet>
    <Code Language="CSharp">
			<![CDATA[
				public DataSet GetResultSet(string query)
				{
					DataSet resultSet = new DataSet();
					using (OleDbConnection connection = new OleDbConnection(""))
					{
							connection.Open();
							using (OleDbDataAdapter adapter = new OleDbDataAdapter(query, connection))
							{
									adapter.Fill(resultSet);
							}
					}
						return resultSet;
					}
			] ]>
		</Code>
</Snippet>






<CodeSnippets
	xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
	<CodeSnippet Format="1.0.0">
		<Header>
			<Title>MyCode</Title>
		</Header>
		<Snippet>
			<Code Language="CSharp">
				<![CDATA[
						public DataSet GetResultSet(string query)
						{
								DataSet resultSet = new DataSet();
								using (OleDbConnection connection = new OleDbConnection(""))
								{
										connection.Open();
										using (OleDbDataAdapter adapter = new OleDbDataAdapter(query, connection))
										{
												adapter.Fill(resultSet);
										}
								}
								return resultSet;
						}
					] ]>
			</Code>
		</Snippet>
	</CodeSnippet>
</CodeSnippets>








Picture showing 'Code Snippets Manager..' option in tools menu
Click to Enlarge



Picture showing Code Snippets Manager pop up window
Click to Enlarge





Picture showing 'Snippet' folder in Code Snippets Manager pop up window
Click to Enlarge




Use Code Snippet In Your Project Later




Picture showing how 'Snippet' folder is displayed when 'CTRL + K + X' is pressed
Click to Enlarge



Picture showing the 'MyCode' snippet
Click to Enlarge




Summary





Posted By  -  Karan Gupta
 
Posted On  -  Saturday, December 31, 2011

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250