Tuesday, September 2, 2014

onblur event/function to SharePoint form fields using JQuery

1.Add JQuery Library to SharePoint from Page

2.write the following code in document.ready function
3.in this example we getting two values from a,b and calculated displayed in c column

$(document).ready(function(){

   var textarea=$("input[title='c']");
          textarea.blur(function(){            
              calculateAmount();        
         });

});
function   calculateAmount()
{
 var a=document.getElementById('trAddition').getElementsByTagName('td')  [1].getElementsByTagName('input');
 var b=document.getElementById('intercost').getElementsByTagName('td')  [2].getElementsByTagName('input');
 var c=document.getElementById('intercost').getElementsByTagName('td')  [3].getElementsByTagName('input');
c.value=a.value+b.value
}


In the above example we are getting the tr td's that contains
a,b and c column values

Get Current Date using Javascript


we can get current date using following code:

 var Currentdate = new Date();
     var DateNow = (Currentdate.getMonth() + 1) + '/' + Currentdate.getDate() + '/' +  Currentdate.getFullYear()

Monday, September 1, 2014

Remove hyperlink from the people picker in sharepoint dataview

 we can remove html tags from people picker using following code

in general we are using field name ex:author
instead of this we can use author.title
it displays author name 

<xsl:value-of select="@author.title" />

But again it displays hyperlink

But using following code we can displays user name directly without hyperlink
 

Saturday, August 30, 2014

Datetime control show Let us know why you need access to this site.

DateTimeControl field uses the iframe calender page to render the actual calender. The location of iframe.aspx is C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS
The problem appeared to be with managed paths in the site collections, the Users with "Contribute access" were accessing the following path:
http://myserver/_layouts/iframe.aspx (Path to Root site collection where user doesn't have access)

The solution:

using  C#:
------------

<SharePoint:DateTimeControl ID="dtcStartDate" runat="server" DateOnly="true"/>

dtcStartDate.DatePickerFrameUrl = SPContext.Current.Web.Url + "/_layouts/iframe.aspx"; 

OR 

<SharePoint:DateTimeControl ID="dtcStartDate" runat="server" DateOnly="true" DatePickerFrameUrl="../../_layouts/iframe.aspx"/>



In sharepoint views:
 --------------------------
<SharePoint:DateTimeControl runat=server  id="dtctrlStartDate" DateOnly="true" DatePickerFrameUrl="../../_layouts/iframe.aspx"/>
 

Remove all html tags in string using jquery


1.Add Jquery Library to your page and write following code in document.ready function.

using bellow code we get pain text from the html :


var myContent = '
Hello world!
';

alert($(myContent).text());

alert message show : Hello word!

Tuesday, August 26, 2014

Attach event receiver to specific list/lists

SharePoint 2010 Event Receiver: -Attach event receiver to specific lists.
............................................................
Creating Event Receiver:
Open visual studio2013 --- > Click on new project ----- >
give name: SampleEvent& Location: C:\solutions\sampleEvent---- >
next Click on Ok button.--- > Click on solution explorer
next give siteurl and select deploy as
a farm solution click on finish. Next right click on solution -- >add --- >
NewItem -- >select SharePoint-- >2010
-- >select event receiver give name:sampleEvent --- >Add
Select event receiver type as List item events from dropdown,
Event source as Customlist from dropdown, check required event
(ex: An Item is being added) next click on finish button. Write required code in Receiver1.cs file
Ex:
namespace EventReciever.EventReceiver11
{
///

/// List Item Events
///
public class EventReceiver11 : SPItemEventReceiver
{
///

/// An item is being added.
///
public override void ItemAdding(SPItemEventProperties properties)
{
base.ItemAdding(properties);
GetValues(properties);
}
void GetValues(SPItemEventProperties properties)
{
try
{
// Get a reference to the current site.
SPWeb currentWeb = properties.OpenWeb();
// Get a reference to the list.
SPList lstAstatus = currentWeb.Lists["AlgorithmStatus"];
SPListItem ListItem = lstAstatus.Items.Add();
ListItem["LoginName"] = currentWeb.CurrentUser.Name;
ListItem["Task"] = "AlgorithmCalculation";
ListItem["Status"] = "C";
this.EventFiringEnabled = false;
ListItem.Update();
this.EventFiringEnabled = true;
}
catch
{
}
}
}
}
- In Solution Explorer open “Elements.xml”
To use an event receiver for one specific list:
- Replace the attribute “ListTemplateId” with “ListUrl” and add your url as value:
------------------------------------------------------------------------------------

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
 
 <Receivers  ListTemplateID="100">
      <Receiver>
        <Name>LogHistoryItemDeleting</Name>
        <Type>ItemDeleting</Type>
        <Assembly>$SharePoint.Project.AssemblyFullName$</Assembly>
        <Class>Axalta.Global.DpciformsLogHistory.LogHistory.LogHistory</Class>
        <SequenceNumber>10000</SequenceNumber>
      </Receiver>
  </Receivers>

</Elements>
--------------------------------------------------------------------------------------
-> Replace With:
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">  
 <Receivers  ListUrl="Lists/NotesCda">
      <Receiver>
        <Name>LogHistoryItemDeleting</Name>
        <Type>ItemDeleting</Type>
        <Assembly>$SharePoint.Project.AssemblyFullName$</Assembly>
        <Class>Axalta.Global.DpciformsLogHistory.LogHistory.LogHistory</Class>
        <SequenceNumber>10000</SequenceNumber>
      </Receiver>
  </Receivers>
</Elements>
… Tip:
To use an event receiver for two or more lists:
You have to add one more “&ltReceivers&gt” node
Sample:
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">  
 <Receivers  ListUrl="Lists/List1">
      <Receiver>
        <Name>LogHistoryItemDeleting</Name>
        <Type>ItemDeleting</Type>
        <Assembly>$SharePoint.Project.AssemblyFullName$</Assembly>
        <Class>Axalta.Global.DpciformsLogHistory.LogHistory.LogHistory</Class>
        <SequenceNumber>10000</SequenceNumber>
      </Receiver>
  </Receivers>

 <Receivers  ListUrl="Lists/List2">
      <Receiver>
        <Name>LogHistoryItemDeleting</Name>
        <Type>ItemDeleting</Type>
        <Assembly>$SharePoint.Project.AssemblyFullName$</Assembly>
        <Class>Axalta.Global.DpciformsLogHistory.LogHistory.LogHistory</Class>
        <SequenceNumber>10000</SequenceNumber>
      </Receiver>
  </Receivers>
</Elements>

Hide the SharePoint ribbon in a custom list form

Apply following style in forms(new/edit/disp):
it hide the ribbon
<style type="text/css">
#s4-ribbonrow{ display:none; }
</style>