Tuesday 23 July 2013

Create Custom Groups in SharePoint Using C#


public void CreateCustomGroup()
        {
            Hashtable groupList = new Hashtable();
            SPUser sUser = null;
            object lobj = null;

            try
            {
                groupList.Add("My_Custom Group", "Will have all kind of access to the application");
                groupList.Add("My_Custom Group_For_USer", "Will have all kind of access to the application");
           
                using (SPWeb oweb = SPSite.OpenWeb())
                {
                  SPUSer  aUser = oweb.CurrentUser;
                    IDictionaryEnumerator lDE = groupList.GetEnumerator();
                    lobj = new object();
                    while (lDE.MoveNext())
                    {
                        if (!this.IsGroupExist(oweb.SiteGroups, lDE.Key.ToString()))
                        {
                            mSPWeb.AllowUnsafeUpdates = true;
                            mSPWeb.SiteGroups.Add(lDE.Key.ToString(), sUser, sUser, Convert.ToString(lDE.Value.ToString()));
                            if (lDE.Key.ToString().Contains("My_Custom Group"))
                            {
                                this.SetRoleDefinition(Convert.ToString(lDE.Key.ToString()),"permission Level Name");
                            }
                            else if (Convert.ToString(lDE.Key.ToString()).Contains("My_Custom Group_For_USer", "Will have all kind of access to the application");
              "))
                            {
                               this.SetRoleDefinition(Convert.ToString(lDE.Key.ToString()),"permission Level Name");
                            }
                       
                        }
                    }
                }
            }
            catch (Exception e)
            {
         
                throw e;
            }
         
        }

Create Permission Level in SharePoint

Create  Permission Level in SharePoint :-

   public void CreatePermissionLevels(bool aOverwriteRoleDefinition)
        {
            SPRoleDefinition aRoleDefinition = null;
            SPBasePermissions aBasePermission;
            SPRoleDefinition spRoleDefinition = null;
            string[] strarrRoleDefName = { "Admin No List Delete"};
            string[] strarrRoleDesc = { "Description of admin No list Delete"};

            try
            {
                using (SPWeb oweb = Site.OpenWeb())
                {
                    aRoleDefinition = oweb.RoleDefinitions.GetByType(SPRoleType.Contributor);
                   aBasePermission = aRoleDefinition.BasePermissions;
                   spRoleDefinition = null;
                    for (int i = 0; i < strarrRoleDefName.Length; i++)
                    {
                        if (!this.SPRoleDefinitionExists(strarrRoleDefName[i], false))
                        {
                            spRoleDefinition = new SPRoleDefinition();
                            switch (strarrRoleDefName[i])
                            {
                                case "Admin No List Delete":
                                    aBasePermission-= SPBasePermissions.ManageLists;
                                    spRoleDefinition.BasePermissions = aBasePermission;
                                    break;
                            }
                            spRoleDefinition.Name = strarrRoleDefName[i];
                            spRoleDefinition.Description = strarrRoleDesc[i];
                            oweb .AllowUnsafeUpdates = true;
                            oweb .RoleDefinitions.Add(spRoleDefinition);
                            oweb .Update();
                            oweb .AllowUnsafeUpdates = false;
                        }
                    }
                }
            }
           
        }

Adding Permission Level to SharePoint Group using C# Code

Adding  Permission Level to  SharePoint Group using C# Code:

private void SetRoleDefinition(string groupName, string permissionLevel)
        {

            SPRoleAssignment roleAssignment = null;
            try
            {
                using (SPWeb oweb =Site.OpenWeb())
                {
                    roleAssignment = new SPRoleAssignment(oweb.SiteGroups[groupName]);
                    roleAssignment.RoleDefinitionBindings.Add(oweb.RoleDefinitions[permissionLevel]);
                    oweb.RoleAssignments.Add(roleAssignment);
                    oweb.AllowUnsafeUpdates = true;
                    oweb.Update();
                    oweb.AllowUnsafeUpdates = false;
                }
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                roleAssignment = null;
            }

        }

Cehck if Group already exsits or not in sharepoint Site

  private bool IsGroupExist(SPGroupCollection groupCollection, string aGroupName)
        {
            SPGroup Group = null;
            try
            {
                Group = groupCollection[aGroupName];
                return true;
            }
            catch
            {
                return false;
            }
        }



What are the Type Selectors in Jquery

1.JQUERY TYPE SELECTORS
input[type="text"].css(‘color’,’blue’);      //jquery Text selectors
$('textarea') .css(‘color’,’blue’);                //jquery TextAreaSelectors
input[type="hidden"].val();                       //jquery Hidden Selectors
input[type="password"]                         //jquery password selctors
$('select')     // jQuery dropdown selector
input[type="radio"]  //jQuery Radio Selectors
input[type="checkbox"]  //jQuery checkbox selector
$('image')  //jQuery image selector

input[type="button"]  //jQuery button selector
2.  JQUERY ID SELECTORS
$("#ID")     //Select any elements by ID (#) denotes ID
3. Jquery Class Selectors
 $(“.classname")   //Select any elements by class name ( . ) denotes Class
4. Attribute Exist selectors
$([attribute name])    //select all elements in a page which have a specific attribute.
Ex.   $("[border]").css(‘color’,’red’);

Jquery Selectors Part II

Selector
Example
Description
:reset
$(":reset")
selected All input elements with type="reset".
:hidden
$("p:hidden")
Selected All hidden p elements.
:visible
$("tr:visible")
Selected All visible table rows
:empty
$(":empty")
Selected All elements with no child of the elements.
:contains(text) 
$(":contains(‘hello')")
Select All elements which contains is text.
[attribute]
$("[href]")
Select All elements with a href attribute.
[attribute$=value]
$("a:[href$=.org]")
Selected elements with a href attribute value ending with ".org"
[attribute=value]
$("a:[href=#]")
elected elements with a href attribute value equal to "#".
[attribute!=value]
$("a:[href!=#]")
Selected elements with a href attribute value not equal to "#".

Jquery Selectors Example Part I

Selector
Example
Description
*
$("table *")
Select All Elements.
#id
$("#name")
Selected element with id="name".
.class
$(".name")
Selected elements with class="name".
tag
$("p")
Selected All p elements.
:input
$(":input")
selected All input elements
:text
$(":text")
selected All input elements with type="text"
:button
$(":button")
selected All input elements with type="button".
:password
$(":password")
selected All input elements with type="password"
:radio
$(":radio")
selected All input elements with type="radio"
:checkbox
$(":checkbox")
selected All input elements with type="checkbox".
:image
$(":image")
selected All input elements with type="image".
:file
$(":file")
selected All input elements with type="file".
:submit
$(":submit")
selected All input elements with type="submit"


jQuery Selectors

jQuery selectors is most important aspects of the jQuery library. jQuery library allow you to select elements in your HTML document by wrapping them in $(" ") (also you have to use single quotes), which is the jQuery wrapper. Selectors are useful and required at every step while using jQuery.
jQuery Selector Syntax
jQuery offers a powerful set of selector operations, which can be used like wild cards to identify specific elements in a page.  

Selector 
Description
TagName
Selects all element match of given elements.
this
Selects current elements.
#ID
Selects element whose id is match of given elements.
.CLASS
Selects element whose class is match of given elements.
Selects all elements in the document.

Jquery Syntax

jQuery syntax is made by using HTML elements selector and perform some action on the elements are manipulation in Dot sign(.)
jQuery syntax: $(selector).method()
$ sign define the jQuery,
Selector define the Query Elements in HTML document, and

method() define the action performed on the elements

From Where I can Start Jquery ??

INSTALL JQUERY :-

First of all we have to need Jquery library file before writing any code on Jquery . Download latest version of jquery.js file from www.jquery.com Website.
Current version is 1.8.0 is Select the Production (32KB, Minified and Gzipped) and click on Download  jquery-1.10.2.min.js/jquery-1.10.2.js.
How to use jQuery Library?
So first thing is that you need to Add Jquery Library on Page.
Ex:-
<html><head>  <script type="text/javascript" src="jquery-1.8.0.min.js"></script>
<script type="text/javascript">   $(document).ready(function() {
      $("div").click(function() {  alert("Wel-Cometo the jQuery..!");  });   });   </script>
</head>
<body>
<div id=“test">
Hey welcome to Jquery.

</div></body></html>