Monday, 22 September 2014

Generating popup window using java script in sharepoint by click on the Button

function popupWindow()
{
var options = SP.UI.$create_DialogOptions();
options.width = 700;
options.height = 300;
options.url = "http://servername:Portnumber/sitename/Lists/ListName/CustomNew.aspx";
options.dialogReturnValueCallback = Function.createDelegate(
null, participant_DialogCallback);
SP.UI.ModalDialog.showModalDialog(options);
}

Here CustomNew is a aspx page created via Sharepoint Designer.


function participant_DialogCallback(result,value)
{
window.location.href = "http://servername:Portnumber/sitename/SitePages/HomePage.aspx";


}

<button type="button" id="btnAssign" onclick="javascript:popupWindow();"> Assign</button>

Here we are going to created button called as Assign, whenever user clicks on the button, popupWindow was going to fire. The above line of code we can place in  inline.

Programmatically create a custom permission level in sharepoint

public void CreateCustomPermissionLevel()
        {
            try
            {
                using (SPSite site = new SPSite(SPContext.Current.Site.Url))
                {
                    using (SPWeb web = site.OpenWeb())
                    {
                        SPRoleDefinition role = new SPRoleDefinition();
                        role.Name = "CustomRole_Add_Edit";
                        role.Description = "Description: Custom Permission level";
                        role.BasePermissions =
                                               SPBasePermissions.AddAndCustomizePages |
                                               SPBasePermissions.ApplyStyleSheets |
                                               SPBasePermissions.AddListItems |
                                               SPBasePermissions.EditListItems |
                                               SPBasePermissions.ViewListItems |
                                               SPBasePermissions.OpenItems |
                                               SPBasePermissions.ViewVersions |
                                               SPBasePermissions.CreateAlerts |
                                               SPBasePermissions.ViewPages;
                        web.RoleDefinitions.Add(role);
                    }
                }
            }
            catch (Exception ex)
            {
              
            }
        }

Thursday, 18 September 2014

Programmatically Save the items into SharePoint List by using SPServices

For this code we have to  include Jquery mini file and SPServices file from http://jquery.com/download/
function btnSaveClick(){
 try
 {
 var FirstName= $("#txtfirstname").val();
 var LastName=$("#txtlastname").val();
 var Location=$("#txtlocation").val();

 $().SPServices({
 operation: "UpdateListItems",
 async: false,
 batchCmd: "New",
 listName: "Registration",
 valuepairs: [["col_FirstName",FirstName],["col_LastName",LastName],["col_location",Location]],
 completefunc: function (xData, Status) {

 alert("Succefuly save items into SPList");
 window.frameElement.commitPopup();

 }
 });
 }

 catch (ex) {
 alert('error:' + ex.Message);
 }
 }


Here col_FirstName,col_LastName and col_loaction  are created  list columns
The Bellow Code is Html

<div class="innercontent1">
<div class="Outer">
<asp:Label ID="lblFirstname" runat="server" Text="First Name"></asp:Label>
</div>
<div>
<asp:TextBox ID="txtfirstname" runat="server"></asp:TextBox>
</div>
</div>

<div class="innercontent1">
<div class="Outer">
<asp:Label ID="lblLastname" runat="server" Text="Last Name"></asp:Label>
</div>
<div>
<asp:TextBox ID="txtlastname" runat="server"></asp:TextBox>
</div>
</div>
<div class="innercontent1">
<div class="Outer">
<asp:Label ID="Lbllocation" runat="server" Text="Lcation"></asp:Label>
</div>
<div>
<asp:TextBox ID="txtlocation" runat="server"></asp:TextBox>
</div>
</div>
<div class="innercontent1">
<div>
<asp:Button ID="btnSave"  runat="server" Text="Save" OnClientClick="return btnSaveClick();" />
</div>
</div>

Regards
Tharak
Happy Coding