Tuesday, 18 January 2011

Blocking key in textbox using javascript

To block all key pressed using javascript in asp.net add the vb code that will execute at client side when any key will be pressed .

txt.Attributes.Add("onkeydown", "return RestrictAllKey();")

Add the javascript function when all key is to be blocked
Following code will block the ; to be pressed

function RestrictAllKey()
{
return false;
}


Add following function when a particular key pressed is to be blocked


function RestrictEntry()
{

var keyCode=window.event.keyCode;

if(window.event.keyCode==186)
return false;
else
{
return true;
}
}

Monday, 10 January 2011

Adding User to share point group in Form Authentication


We are running the site on form authentication. when the user is approved by the admin we have add the approved user in SharePoint group. 


So to add the user to sharepoint group user the following code :


            SPUser spUser;
            string accountName="AccountName";
            string sGruupName="GroupName;
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (SPSite spSite = new SPSite(SPContext.Current.Site.ID))
                {
                    using (SPWeb obSPWeb = spSite.RootWeb)
                    {
                        if (!accountName.Contains(":"))
                        {
                            accountName = Membership.Provider.Name + ":" + accountName;
                        }
                        spUser = obSPWeb.EnsureUser(accountName);
                        SPGroup spGroup = obSPWeb.SiteGroups[sGruupName];
                        spGroup.AddUser(spUser);
                    }
                }
});

Saturday, 8 January 2011

Conntecting to WSS internal sql database

Client has installed the WSS without installing the sql server .

So WSS has installed the default instance of SQL server as internal database instance.

We need to connect to the database but was not aware what to do.

Then we have installed the SQL server management studio but don't know the server name.

To connect to default instance we have to use named pipe  as the following  :

\\.\pipe\MSSQL$MICROSOFT##SSEE\sql\query in sever in SQL server management studio.


Using this we was able to connect to sql server and perform the operation we wanted.