|
|
| |
How to make your sharepoint development faster? |
|
| |
SPCodeSnippets provides the most commonly used SharePoint code snippets that follow SharePoint development best practices. Just integrate them into your visual studio, reuse the code and speed up your SharePoint development. |
|
| |
|
|
| |
Code snippets are reusable, task-oriented blocks of code. It can be as simple as creating an exception to add list item in list. They are combined with IntelliSense to increase developer productivity, making them available with a few keystrokes. While you can easily create your own snippets, the Visual Studio 2005 installation includes a set of Visual Basic and Visual C# code snippets. One popular code snippet allows you to easily add a frequently used code block. Code block is added by simply typing prop into your Visual Studio source and hitting [Tab] twice. Snippets are available for many code elements; snippets commonly use language keywords in the IntelliSense pop-up window. All you need to do is select the keyword and hit [Tab] twice to insert the snippet. Some C# examples include: if, for, foreach, switch, while, and using. The for loop code snippet follows: |
|
| |
|
|
| |
How to add Code snippet manager tab in Visual studio environment:- |
|
| |
|
|
| |
 |
|
| |
|
|
| |
Under command menu select tools in categories section and drag up on tools tab. |
|
| |
|
|
| |
 |
|
| |
|
|
| |
Code Snippets Manager tab added. |
|
| |
|
|
| |
 |
|
| |
Create your own code snippets |
|
| |
Code snippets are built with XML; they are contained in their own files using the .snippet file extension. The XML mark-up in the .snippet file provides snippet metadata, which includes a description, shortcut, title, and the actual code. In addition, Visual Basic or c# code snippets may include code references.
The code below contains the code snippet file. The CodeSnippets element is the root, and it may contain one or more CodeSnippet elements. Its metadata is defined in the Header element. The name that appears in the IntelliSense pop-up window is defined by the Shortcut element. The Declarations element is optional — it defines replaceable sections of the snippet. The Code element specifies the code that is actually inserted when the snippet is used. Visual Studio includes the Code Snippets Manager to manage snippets. |
|
| |
|
|
| |
<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>splistitem</Title>
<Shortcut>splistitem</Shortcut>
<Description>Code snippet Adding listitem in List</Description>
<Author>Mahesh</Author>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
<SnippetType>SurroundsWith</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>SPWebRootName</ID>
<ToolTip>SPWeb Object name</ToolTip>
<Default>oSPWebroot</Default>
</Literal>
<Literal>
<ID>SPWebName</ID>
<ToolTip>SPWeb Object name</ToolTip>
<Default>oSPWeb</Default>
</Literal>
<Literal>
<ID>SPSiteName</ID>
<ToolTip>SPSite Object name</ToolTip>
<Default>oSPSite</Default>
</Literal>
<Literal>
<ID>SPListName</ID>
<ToolTip>SPList Object name</ToolTip>
<Default>oSPList</Default>
</Literal>
<Literal>
<ID>SPListItemName</ID>
<ToolTip>SPListItem Object name</ToolTip>
<Default>oSPListItem</Default>
</Literal>
</Declarations>
<Code Language="csharp">
<![CDATA[SPWeb $SPWebRootName$ = SPContext.Current.Web;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite $SPSiteName$ = new SPSite($SPWebRootName$.Site.ID))
{
using (SPWeb $SPWebName$ = $SPSiteName$.OpenWeb($SPWebRootName$.ID))
{
SPList $SPListName$ = $SPWebName$.Lists["User List"];
SPListItem $SPListItemName$ = $SPListName$.Items.Add();
$SPWebName$.AllowUnsafeUpdates = true;
$SPListItemName$["Title"] = "";
$SPListItemName$.Update();
$SPWebName$.AllowUnsafeUpdates = false;
}
}
});
]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets> |
|
| |
Save as Add a listitem in list.snippet |
|
| |
 |
|
| |
|
|
| |
Select Visual C# and Click add button and select the folder where Snippets files are stored. |
|
| |
 |
|
| |
Right click on our code behind file and select Insert Snippet tab and double click it. |
|
| |
 |
|
| |
Here is the code block added through code snippets. |
|
| |
 |
|
| |
|
|
| |
The LANGUAGE portion of the path is replaced by the language being used like VB, VC#, and XML. Look at the C# prop code snippet to get a better idea of how they are coded. The prop code snippet is in the following directory: C:\Program Files\Microsoft Visual Studio 8\VC#\Snippets\1033\Visual C#\Visual C# |
|
| |
|
|
| |
For SPCodesnippets download. Please check this link |
|
| |
http://code.msdn.microsoft.com/SPCodeSnippets |
|
| |
|
|