Search This Blog

2011-02-05

Create A Simple Feature

Step 1-Create A class library project "MyFeature" in C#
Step 2-Add reference "Windows Sharepoint Services"
Step 3-Create a folder "Features" under the class library and a a folder "MyFeature" under the "Features" folder
Step 4-Add a XML file "Feature.xml" under "MyFeature" folder
Step 5-Add a schema file to your XML from the following path-
C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\XML\wss.xsd
Step 6-The content of the feature.xml will be as follows
<Feature xmlns="http://schemas.microsoft.com/sharepoint/"
Id="0222472A-0CF1-46bc-8B65-3F319C7B3DBE"
Title="My Feature"
Description="This is my first feature"
Hidden="false"
Scope="Web"
ImageUrl="menuprofile.gif"
ReceiverClass="MyFeature.MyFeatureReceiver"
ReceiverAssembly="MyFeature, Version=1.0.0.0, Culture=neutral, PublicKeyToken=30534ee939de1c1d"
>
<ElementManifests >
<ElementManifest Location="Elements.xml"/>
</ElementManifests>
</Feature>


The Id Value must be unique and will be generated from Tools->Guid Generator".Title ,description and image will be displayed in the feature list of your web site.Scope can be Farm,WebApplication,Site,Web depending on the scenario.
ReceiverClass and ReceiverAssembly will be explain in the next section.
ElementManifests element will call another xml.

Step 6-Add "Elements.xml" under "MyFeature" folder.
The content of the Elements.xml will be as follows-
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Module Name="MyModule" Path="" Url="">
<File Url="MyModule.aspx"
Type="Ghostable"
IgnoreIfAlreadyExists="FALSE">
</File>
</Module>
<CustomAction Id="SiteActionsToolbar"
GroupId="SiteActions"
Location="Microsoft.SharePoint.StandardMenu"
Sequence="1000"
Title="Go To MyModule"
ImageUrl="~/_layouts/images/menuprofile.gif">
<UrlAction Url="~site/MyModule.aspx"/>
</CustomAction>
</Elements>

CustomAction element defines where the feature will be displayed after activation.
UrlAction element defines the url of the aspx page.But to access the url we first need to define File url.

Step 7-Add a text file "MyModule.aspx" under the "MyFeature" folder.The content will be as follows
<%@ Page Language="C#" MasterPageFile="~masterurl\default.master" %>
<asp:Content ContentPlaceHolderID="PlaceHolderMain" runat="server">
<h2>Hello , This is my test page</h2>
</asp:Content>

Step 8-Add a class file under the class library
"MyFeatureReceiver.cs"


The content will be as follows
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;

namespace MyFeature
{
public class MyFeatureReceiver:SPFeatureReceiver
{
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
SPWeb site = (SPWeb)properties.Feature.Parent;
// SPWeb site = SPContext.Current.Web;//when the scope of the feature is site
// track original site Title using SPWeb property bag
site.Properties["OriginalTitle"] = site.Title;
site.Properties.Update();
// update site title
site.Title = "My Feature has been activated";
site.Update();
}

public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
{
// reset site Title back to its original value
SPWeb site = (SPWeb)properties.Feature.Parent;
//SPWeb site = SPContext.Current.Web;//when the scope of the feature is site
site.Title = site.Properties["OriginalTitle"];
site.Update();

}

public override void FeatureInstalled(SPFeatureReceiverProperties properties)
{
}

public override void FeatureUninstalling(SPFeatureReceiverProperties properties)
{
}
}
}


Step 9-Add a strong name to your class library ,build it and copy the dll to GAC
Step 10-Open the Feature.xml and write the ReceiverClass,ReceiverAssembly according to your "MyFeatureReceiver.cs"

Your solution structure will be as follows-


Step 11-Copy your "MyFeature" folder (which is under the "Features" folder) to the following location
C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES

Step 12-Install your feature by the following command in the command prompt-
stsadm -o InstallFeature -name MyFeature -force

Stsadm exe will be found in the following path
C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN\STSADM.EXE

Step 13-Activate your feature from the site setting->site features


Step 14-After activation , you will find the title and label under the menu


Step 15-Click on the "Go To MyModule" ,you will be navigated to your MyModule.aspx



Step 16-After deactivation of your feature ,all of these thing will be undone.

2010-05-31

Different Isolation Level in SQL Server 2005

There are four types of isolation level as follows
READ UNCOMMITTED
READ COMMITTED
REPEATABLE READ
SERIALIZABLE


Read uncommitted:When it's used, SQL Server not issue shared locks while reading data. So, you can read an uncommitted transaction that might get rolled back later. This isolation level is also called dirty read. This is the lowest isolation level. It ensures only that a physically corrupt data will not be read.

Read committed:This is the default isolation level in SQL Server. When it's used, SQL Server will use shared locks while reading data. It ensures that a physically corrupt data will not be read and will never read data that another application has changed and not yet committed, but it does not ensure that the data will not be changed before the end of the transaction.


Repeatable read:When it's used, the dirty reads and nonrepeatable reads cannot occur. It means that locks will be placed on all data that is used in a query, and another transactions cannot update the data.

Serializable:Most restrictive isolation level. When it's used, then phantom values cannot occur. It prevents other users from updating or inserting rows into the data set until the transaction is complete.

SET TRANSACTION ISOLATION LEVEL
{
READ COMMITTED
| READ UNCOMMITTED
| REPEATABLE READ
| SERIALIZABLE
}

SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
GO
DBCC USEROPTIONS
GO



Different Concurrency Level:

Nonrepeatable read
When a transaction reads the same row more than one time, and between the
two (or more) reads, a separate transaction modifies that row. Because the
row was modified between reads within the same transaction, each read
produces different values, which introduces inconsistency.Nonrepeatable read—Nonrepeatable reads happen when a transaction performs the same query two or more times and each time the data is different. This is usually due to another concurrent transaction updating the data
between the queries.

Dirty read—Dirty reads occur when one transaction reads data that has been written but not yet committed by another transaction. If the changes are later rolled back, the data obtained by the first transaction will be invalid.


phantom
Phantom behavior occurs when a transaction attempts to select a row that
does not exist and a second transaction inserts the row before the first
transaction finishes. If the row is inserted, the row appears as a phantom
to the first transaction, inconsistently appearing and disappearing.

2010-05-02

How to get records in random order from a sql query in sql server?

In SQL Server we can get records in random order from a sql query using NEWID() Function like:

SELECT Subject FROM dbo.test ORDER BY NEWID()

What are the default databases of SQL Server

Microsoft SQL SERVER Provides 4 default databases

1.Master (Controls other Databases):The Master database holds information for all databases located on the SQL Server instance and is the glue that holds the engine together. Because SQL Server cannot start without a functioning master database, you must administer this database with care.

2.Model (Template for new Databases)

3.Msdb (Scheduling and Job Information):The msdb database stores information regarding database backups, SQL Agent information, DTS packages, SQL Server jobs, and some replication information such as for log shipping.

4.Tempdb (Temporary Storage):The tempdb holds temporary objects such as global and local temporary tables and stored procedures. The model is essentially a template database used in the creation of any new user database created in the instance.