Tuesday, 25 September 2012

pass value from gridview javascript function

Friday, 31 August 2012

How to set 2 two background image using css style class in body tag elements html

HTML CSS Tricks 1: ( To apply background image for whole page )

We could set two background images using html and body tag elements in CSS styles class.
The below sample code snippet used to set the background image (tile.jpg) / color for the whole page (html css) and bc_head.png image has to be displayed just above the background tile image / color.
 
html {
                    background: #000 url("images/tile.jpg")  repeat;
                }                            
body {
                    background: url("images/bc_head.png")  repeat-x;
                    background-position: left top;
               

HTML CSS Tricks 2:( To apply background image for not whole page and only for body  )


To apply background image for not whole page and only for body, Consider the following code.
We can create table / div elements inside body tag and write css style class names.

HTML Source:

<body>
<table> <tr>
<td class="a"><div class="b">...</div></td>
</tr></table>
 </body>

CSS style Class name:

.a
{
  background-image: url(a.png);
}
.b
{
  background-image: url(b.png);
}

Thursday, 30 August 2012

How do check if file or image url exists using jQuery or Javascript json js ajax


Approach 1: (If its any file with any extension) :

To check whether files exist in file system, the best way to do this is with an AJAX HEAD request. HEAD requests only ask for and return the header from the destination file, so they’re much faster than POST or GET requests. Perfect for a simple file check.
It’s also returns the content length and last modified date and that jQuery has an “ifModified” option for the .ajax function that returns a Boolean value.
This jquery / javascript /js will be useful to check the image / file existence by providing source complete URL path  or relative URL path

Sample Demo Code

$.ajax({
    url:images/header.jpg',
    type:'HEAD',
    error:
        function(){
            alert(‘no File exist);
        },
    success:
        function(){
            alert(‘File exist’);        }
});

Approach 2 : (If its Image File with its related extension.)

The above approach is most recommended since this approach is not that much reliable and performance when compared to it to check existence.

HTML Source:
<img id=”image_id” src=” images/header.jpg” alt=”” />

JQuery:

This Jquery js will get call automatically when image is not available / loaded 
from file system or repository or directory.
 
$('#image_id').error(function() {

  alert('Image does not exist !!');

});
 

Wednesday, 22 August 2012

class library dll’s not added / installed / referenced / moved to assembly GAC while deployment of package automatically in SharePoint SP 2010 / 2007

To install classlibrary dll to GAC automatically during the deployment of WSP package of Sharepoint SP 2007 / 2010, refer the following instruction steps,

1. Open the Package designer in the SharePoint project.
2. Select the Advanced tab.
3. Click the Add button.
4. Select the Add Assembly from Project Output menu item.
5. Use the Source Project dropdown to select which project in your solution should have its assembly included.
6. Make sure the Deployment Target is set to GlobalAssemblyCache.
7. Click OK.
8. Repackage and redeploy the SharePoint project. 

The WSP package should now contain the class library's assembly and the WSP's package manifest should have been updated according.,

For more details, please refer : 

Tuesday, 14 August 2012

How to delete Corrupted / errored list / picture library in SharePoint SP 2010 /2007

The reason for  error like " Exception from HRESULT 0×81070215  " is custom list definition and list instance is not properly defined. That means field / columns in the content type has issues with that (some necessary fields / column might not be be defined there)
Please try to fix this by doing correct list definition, list instance and its content type otherwise delete the list using stsadm.exe force delete command

If you receive error Exception from HRESULT 0×81070215 when you open a list in browser or access the SharePoint site manager, a list has not properly been deleted and is in a corrupted state, which means you can not able to delete using browser hence you have to delete the corrupted list using stsadm forcedeletelist command.

Steps:

  • Go to start->run->cmd (it will open command window)
  • For Sharepoint 2007, Use cd C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\BIN
  •  For Sharepoint 2010, Use cd C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\BIN.
  • To find the help for forcedeletelist user following command,
    • Stsadm –help forcedeletelist
  • To delete particular corrupt list use following command,

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();
  }
}