Monday, 30 July 2012

Call or acess wcf webservice using ajax jquery code in asp.net c# javascript js

This code sample demonstrate how to pass with or without parameters to WCF service / web service method from client side code ajax jquery json js.
Unlike Javascript, Jquery provides rich access to service method in asp.net c#
 
With Parameters Sample

Client side code with dynamic and static text parameter to web service method from ajax json js With Parameters:-
 
function CallService()  
 { 
      var msg = ‘test message’;
     $.ajax( 
     { 
         Type: "POST", 
         contentType: "application/json; charset=utf-8",
         url: "ServiceName.asmx/WebMethodName", 
         data: "{ 'message': '"+msg+"' , ‘name’: 'test name' }",
         success: function (msg) { 
         alert(msg.d); 
         } 
     });

Server Side webservice / WCF method code :
 
[WebMethod()]
public static string WebMethodName(string message, string name)
{
return message + “--” + name;
}

Without Parameters Sample

Client side code without parameter to web service method from ajax json js With Parameters:-
 
function CallService()  
 { 
     $.ajax( 
     { 
         Type: "POST", 
         contentType: "application/json; charset=utf-8",
         url: "ServiceName.asmx/WebMethodName", 
         data: "{  }",
         success: function (msg) { 
         alert(msg.d); 
         } 
     });

Server Side webservice / WCF method code :

[WebMethod()]
public static string WebMethodName()
{
return “success”;
}

Thursday, 26 July 2012

Hiding / showing the SharePoint SP 2010 Ribbon From Anonymous restricted limited access Users in master edit page Privilege


How to hiding or showing ribbon control (with navigation breadcrumb) for anonymous or read access users like visitor or limited access users in sharepoint 2010 ( SP 2010 ) dynamically based on user's access:


SharePoint 2010 introduced new feature called “ Ribbon “ and it provides great user experience for users with elevated privileges, like contributors and site owners. However, Its not suggested for users with lease privilege, such as visitors and anonymous users since most of features are applicable for them.
SPSecurityTrimmedControl which  is used to show / hide the ribbon control.

Steps:

1)      Open your SharePoint master page to edit it.

2)      Find the following line wth the highlighted text in your master page.

       <div id="s4-ribbonrow" class="s4-pr s4-ribbonrowhidetitle">
     Note: This div only contains the whole part of out of box sharepoint ribbon control.

3)  To hide the above div element, Find the following line in your master page.

      <div id="s4-workspace"

4)  Now add the following code in your master page just above the “s4-workspace” div element.

   <Sharepoint:SPSecurityTrimmedControl ID="SPSecurityTrimmedControl2" runat="server" PermissionsString="ManagePermission">
    <script type="text/javascript">
        document.getElementById("s4-ribbonrow").style.display = "none";
    </script>
</
Sharepoint:SPSecurityTrimmedControl>

5)      To apply changes, Save the master page and publish it.




Assigning permission programmatically for document libray or list item sharepoint 2010 code sp 2010


How to access or Assigning permission dynamically to Document library / List library / List Item / picture library on folder in sharepoint 2007 / 2010 ( SP 2010 ) code :

Windows SharePoint 2010 / 2007 provides Services manages permissions through Roles and Responsibilities. SPRoleDefinition and SPRoleDefinition classes provides methods to assign users to roles such as “Contributor” or “Site Owner” or “Reader.

Sample solution code:

Following code demonstrate how to assigning / access “Reader” to custom SharePoint group “customgroup” programmatically on Folder of a document library for a custom sharepoint group by code method

using (SPSite site = new SPSite(siteCollection))
{
  using (SPWeb web = site.OpenWeb(siteName))
  {
    SPDocumentLibrary docLib = (SPDocumentLibrary)web.Lists[libraryName];
    //Get folder
    SPListItem item = docLib.Folders[1];
    if (!item.HasUniqueRoleAssignments)
      item.BreakRoleInheritance(true);
    SPRoleAssignment roleAssignment = new SPRoleAssignment(“customgroup”);
    SPRoleDefinition roleDefination = web.RoleDefinitions["Reader "];

    roleAssignment.RoleDefinitionBindings.Add(roleDefination);
    item.RoleAssignments.Add(roleAssignment);
    item.Update();
  }
}

Assigning permission programmatically for site collectin and its sub site item sharepoint 2010 code sp 2010

How to Assigning permission programmatically / dynamically to site collection or its sub site in sharepoint 2007 / 2010 ( SP 2010 ) code

Windows SharePoint 2010 / 2007 (SP 2010) Service manages permissions through Roles and Responsibilities. SPRoleDefinition and SPRoleDefinition classes provides methods to assign users to roles such as “Contributor” or “Site Owner” or “Reader

Sample solution code:

Following code demonstrate how to assign / access  “Reader” to custom SharePoint group “customgroup” programmatically / dynamically by code class method and access the site collection and its sub sites as “reader” permission in sp2010.


using (SPSite site = new SPSite(siteCollection))
{
  using (SPWeb subWeb = site.OpenWeb(siteName))
  {
    //You need to break role inheritence if you want to assign unique permission to subsite
    if (!subWeb.HasUniqueRoleAssignments)
      subWeb.BreakRoleInheritance(true);
    SPRoleDefinition roleDefination = parentWeb.RoleDefinitions["Reader"];
    SPRoleAssignment roleAssignment = new SPRoleAssignment("customgroup");
    roleAssignment.RoleDefinitionBindings.Add(roleDefination);
    subWeb.RoleAssignments.Add(roleAssignment);
    subWeb.Update();
  }
}

Wednesday, 25 July 2012

Delete Close Web Parts SharePoint 2010 url


How to delete or close Web Parts on SharePoint 2010 or What is The URL for deleting or closing webparts in sharepoint 2007 / 2010 pages :

Using webpart Maintenance Page mode:


We just need to  go to the Web Part Maintenance Page of SharePoint 2010. and then append just , ?contents=1

This URL of Maintenance Page of SharePoint 2010, will display all webparts which were used in page.
This URL will show all current using webparts and closed webparts ( not deleted webparts).

Sample solution URL for delete or close the webpart would be like,

http://yourdomain.com/pages/home.aspx?contents=1


Using Normal Manual Mode :
 
To delete a Web part, do the following:
1. Open the page where the Web part is located.
2. Select Edit Page from the Site Actions drop-down menu.
3. Click the Web part to be deleted.
4. Click the Web Part Tools tab on the Ribbon.
5. Click the Delete Button, and then click OK in the warning dialog.
 

Monday, 23 July 2012

this implementation is not part of the windows platform fips validated cryptographic algorithms

Problems / Issues with  “ this implementation is not part of the windows platform fips validated cryptographic algorithms ” with visual studio 2010 with windows 7 operating system :-

Solution for this problem is,

enforceFIPSPolicy is a .Net 2.0 SP1 config file switch which helps the application to opt out FIPS checking.

How to  fix / avoid this issue / problem “ this implementation is not part of the windows platform fips validated cryptographic algorithms ” in VS 2010 :-

To avoid the issue with Visual Studio 2010, we could follow the steps,
  • Open Devenv.exe.config from
    C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE “  if your OS is x64 bit
    otherwise “ C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\on x86 OS
  • Do find </runtime> tag and add the following code tags,
    <enforceFIPSPolicy enabled="false"/>
  • After adding the  code into “ devenv.exe. config “ file and it would looks like,
<configuration>
<runtime>
.
.
.
<
enforceFIPSPolicy enabled="false"/>
</runtime>
</configuration>
  • Do restart Visual Studio 2010 / VS 2010