Showing posts with label Javascript/JQuery/AJAX. Show all posts
Showing posts with label Javascript/JQuery/AJAX. Show all posts

Wednesday, May 25, 2011

Customization Using JQuery

Client-Side Programming in Sharepoint # 5 - Customization Using JQuery



Save jquery-1.3.2.js in local document library (Jquery) , and update jquery file references in below scripts.You can placed these script either on the page in SPD editor or in CEWP.

  • List Forms (Edit/Display) - Hide created and modified by block from list forms (Edit, Display)

    <script type="text/javascript" src="/Jquery/jquery-1.3.2.js"></script>
    <script type="text/javascript">
    $(document).ready(function() {
    $('#onetidinfoblockV').hide();
    $('#onetidinfoblock1').hide();
    $('#onetidinfoblock2').hide();
    });
    </script>


  • List Forms (Edit/Display) - Replace created and modified by links with *** in list forms(Edit, Display)

    <script type="text/javascript" src="/Jquery/jquery-1.3.2.js"></script>
    <script type="text/javascript">
    $(document).ready(function() {
    $('a[href*="userdisp.aspx?ID="]').each(function(index) {
    var link = $(this);
    $(this).after("***");
    $(this).remove();
    });
    });</script>



  • List Forms (Edit/Display) - Hide Spell Check image and list from list forms(Edit, Display)

    <script type="text/javascript" src="/Jquery/jquery-1.3.2.js"></script>
    <script type="text/javascript">
    $(document).ready(function() {
    $('a[title*="Spelling..."]').each(function(index) {
    var link = $(this);
    link.parent().parent().hide();
    });

    });</script>


  • Site Header / Logo - Hide Title text from logo -
    Publishing Master Page- e.g. Blueband.master


    <script type="text/javascript" src="/Jquery/jquery-1.3.2.js"></script>
    <script type="text/javascript">
    $(document).ready(function() {
    $('a[class*="zz1_logoLinkId_1"]').each(function(index) {
    var link = $(this);
    if (link.text() == "Employee Portal")
    link.text(link.text().replace("Employee Portal", ""));
    });
    });</script>

    Default Master page - default.master

    <style type="text/css">
    .ms-sitetitle h1
    {
    display:none
    }
    </style>


Tuesday, May 24, 2011

Customize List View Using Jquery

Client-Side Programming in Sharepoint # 4
- Customize List View Using Jquery

SharePoint views allow us to show SharePoint Lists in different ways. You can select subset of columns to show on the tabular grid, Can define sorting, filters, grouping, paging etc on list items. As Views represent logical subset of list record, so a list can have multiple views.
Sometime we need to customize these OOB views that match our requirement, Here are some customization on list views using jquery.Save jquery-1.3.2.js in local document library (Jquery) , and update jquery file reference in below scripts.

  • Remove lookup column hyper link – SharePoint display a lookup fields as an hyperlink to linked item in list view. We can replace this hyperlink with simple no clickable text by JQuery.

    <script type="text/javascript" src="/Jquery/jquery-1.3.2.js"></script>
    <script type="text/javascript">
    $(document).ready(function() {
    $('a[href*="RootFolder=*"]').each(function(index) {
    var link = $(this);
    $(this).after("<span>" + link.text() + "</span>");
    $(this).remove();
    });
    });
    </script>


  • Remove SPUser Hyperlink - SharePoint display a SPUser fields (created by , modified by etc) as an hyperlink to user info list item in list view. We can replace this hyperlink with simple not clickable text by JQuery.

    <script type="text/javascript" src="/Jquery/jquery-1.3.2.js"></script>
    <script type="text/javascript">
    $(document).ready(function() {
    $('a[href*="userdisp.aspx?ID="]').each(function(index) {
    var link = $(this);
    $(this).after("<span>" + link.text() + "</span>");
    $(this).remove();
    });
    });
    </script>


  • Remove Edit Heading for readonly users – We can add Edit Icon on list item view, so when a user will click on this icon they redirect to Edit Item Form. But for an readonly user it will not show any icon in the view table , only column heading say ‘Edit’ . We can remove this heading text using JQuery ..

    <script type="text/javascript" src="/Jquery/jquery-1.3.2.js"></script>
    <script type="text/javascript">
    $(document).ready(function() {
    if ($('a[href*="EditForm.aspx?ID="]').size() <= 0)
    {
    $('TH[scope*="col"]').each(function(index) {
    var link = $(this);
    if (link.text() == "Edit")
    link.text(link.text().replace("Edit", ""));

    });
    }
    });
    </script>


  • Remove start time from calendar view – In a Calendar view SharePoint shows start time of the events & Title. For an Full day event it shows 12.00 AM as an start time. We can remove this 12:00 AM ,as

    <script type="text/javascript" src="/Jquery/jquery-1.3.2.js"></script>
    <script type="text/javascript">
    $(document).ready(function() {
    $('NOBR').each(function(index) {
    var link = $(this);
    if(link.text().indexOf("12:00 AM") >= 0)
    {
    //alert(link.text());
    link.text(link.text().replace("12:00 AM", ""));
    }
    });
    });</script>


  • Remove SPUser Hyperlink From Discussion list’s Flat View - SharePoint display a SPUser fields (created by , modified by etc) as an hyperlink to user info list item in list view. We can replace this hyperlink with simple not clickable text by JQuery.

    <script type="text/javascript" src="/Jquery/jquery-1.3.2.js"></script>
    <script type="text/javascript">
    $(document).ready(function() {
    $('a[href*="userdisp.aspx?ID="]').each(function(index) {
    var link = $(this);
    if (link.children().length <= 0)
    {
    $(this).after("<span>" + link.text() + "</span>");
    $(this).remove();
    }
    else
    {
    //$(this).attr('href', '#');
    $(this).after("<span>" + link.html() + "</span>");
    $(this).remove();

    }
    });
    });</script>


  • remove open in explorer view link (Open With Windows Explorer) from list action menu

    <script type="text/javascript" language="JavaScript">
    var doc = document.getElementsByTagName('ie:menuitem');
    for (var i = 0; i < doc.length; i++)
    {
    itm = doc[i];
    if (itm.id.match('OpenInExplorer')!=null)
    { itm.hidden=true; }
    }
    </script>


Thursday, April 22, 2010

Configure AJAX In Sharepoint 2007

For enabling Ajax in SharePoint 2007, We need first to configure SharePoint Portal to support AJAX. We can do it in following way -
  • Installing ASP.NET AJAX on servers in your farm
    • install the full " AJAX Extensions " from
      ajax.asp.net
    • Download ajextoolkit -
      http://ajaxcontroltoolkit.codeplex.com/releases/view/11121
  • Configure SharePoint to support AJAX & AjaxControlToolkit –
    For enabling Ajax in SharePoint 2007, you need first to configure SharePoint to support AJAX. For this we need to add some configuration settings in web.config file.Locate your default web.config file ("C:\Inetpub\wwwroot\wss\VirtualDirectories\YourWebAppPortNo\web.config").

    • Add the following part under: <configSections>
      <configuration>
      <configSections>
      <sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
      <sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
      <section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication"/>
      <sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
      <section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="Everywhere" />
      <section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication" />
      <section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication" />
      </sectionGroup>
      </sectionGroup>
      </sectionGroup>
      </configSections>
    • add the AJAX controls dll to SharePoint Safe Controls, so copy the following part under: <SafeControls>
      <SafeControls>
      <SafeControl Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Namespace="System.Web.UI" TypeName="*" Safe="True" />
      <!-- Usually not required ,in case of any issues you can try to uncomment this. -->
      <!--<SafeControl Assembly="AjaxControlToolkit, Version=1.0.20229.20821, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e" Namespace="AjaxControlToolkit" TypeName="*" Safe="True" />-->

      </SafeControls>
    • Add the following part under: <httpHandlers>
      <httpHandlers>
      <remove verb="GET,HEAD,POST" path="*" />
      <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
      <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
      <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/>
      </httpHandlers>
    • Add the following part under: <httpModules>
      <httpModules>
      <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
      </httpModules>
    • Add the following part under : <compilation><assemblies> - the version number can change according to your .net installation
      <compilation batch="false" debug="true">
      <assemblies>
      <add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
      <!-- for enabling ajax tool kit support -->
      <add assembly="AjaxControlToolkit, Version=3.0.30930.28736, Culture=neutral, PublicKeyToken=28F01B0E84B6D53E"/>
      </assemblies>
      </compilation>
    • Add the following part under: <pages >
      <pages enableSessionState="false" enableViewState="true" enableViewStateMac="true" validateRequest="false" pageParserFilterType="Microsoft.SharePoint.ApplicationRuntime.SPPageParserFilter, Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" asyncTimeout="7">
      <controls>
      <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
      <!-- Add this to support the Control Kit -->
      <add namespace="AjaxControlToolkit" assembly="AjaxControlToolkit" tagPrefix="cc1"/>
      </controls>
      </pages>
    • At the end of web.config add the following part under:
      <configuration>
      <!--
      <system.web.extensions>
      <scripting>
      <webServices>
      -->
      <!-- Uncomment this line to customize maxJsonLength and add a custom converter -->
      <!--
      <jsonSerialization maxJsonLength="500">
      <converters>
      <add name="ConvertMe" type="Acme.SubAcme.ConvertMeTypeConverter"/>
      </converters>
      </jsonSerialization>
      -->
      <!-- Uncomment this line to enable the authentication service. Include requireSSL="true" if appropriate. -->
      <!--
      <authenticationService enabled="true" requireSSL = "true|false"/>
      -->
      <!-- Uncomment these lines to enable the profile service. To allow profile properties to be retrieved and modified in ASP.NET AJAX applications, you need to add each property name to the readAccessProperties and writeAccessProperties attributes. -->
      <!--
      <profileService enabled="true"
      readAccessProperties="propertyname1,propertyname2"
      writeAccessProperties="propertyname1,propertyname2" />
      -->
      </webServices>
      <!--
      <scriptResourceHandler enableCompression="true" enableCaching="true" />
      -->
      </scripting>
      </system.web.extensions>
      -->
      <!--<system.webServer>
      <validation validateIntegratedModeConfiguration="false"/>
      <modules>
      <add name="ScriptModule" preCondition="integratedMode" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
      </modules>
      <handlers>
      <remove name="WebServiceHandlerFactory-Integrated" />
      <add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode"
      type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
      <add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode"
      type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
      <add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
      </handlers>
      </system.webServer>
      -->
      </configuration>
    • Save your web.config file, restart IIS
  • Include the AJAX script Manager to the master page, e.g.include the script manager control in the default.master(C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\GLOBAL)
    According to your portal template; locate the right master page file or you can open the master page from the SharePoint Designer under _catalogs folder.After you locate the master page file open the file then put the following line inside the top of <form> tag
    As shown below:
    <form runat="server" onsubmit="return _spFormOnSubmitWrapper();">
    <WebPartPages:SPWebPartManager id="m" runat="Server" />
    <asp:ScriptManager runat="server" ID="ScriptManager1"></asp:ScriptManager>
  • Also you should copy the DLL “AjaxControlToolkit.dll” into your SharePoint Bin Folder:
    C:\Inetpub\wwwroot\wss\VirtualDirectories\80\bin
    Also add it on GAC of you are planning to access it from a Shared assembly

Troublshooting -

  • Download the correct version of System.Web.Extensions & ajextoolkit according to .net framework installation.And Change the Version numbers in web.config
  • You can also Get the Sharepoint 2007 AJAX toolkit from CodePlex http://www.codeplex.com/sharepointajax
  • Always keep a backup of the web.config file (important, if something goes wrong you might need to revert to the old one)
  • Make sure SharePoint has access to AjaxControlToolkit.dll. Copy the dll assembly to the BIN/Global Assembly Cache (GAC)
  • In case of accessibility issue for tool kit , copy all AJAXTOOLKIT files and directories to C:\Inetpub\wwwroot\wss\VirtualDirectories\Port\_app_bin folder
  • In case of security issues try to , Add AjaxToolKit.dll to SafeControls in web.config
  • In case of any issues with ScriptManager in your master page - Instead of asp:scriptManager ... add the ToolkitScriptManager to your master page
    <ajaxToolkit:ToolkitScriptManager ID="ScriptManager1" runat="server" />

Tuesday, December 29, 2009

Client-Side Programming in Sharepoint # 3

Set Default Values in Sharepoint List Forms (Newform.aspx / Editform.aspx)


Some time we need to set default values in shaepoint list form. e.g. there may be some requirement where we need to set person or group field with loggedin user in Newform.aspx. We can set default values in list setting page. But, by default at design time, there is no way to set a field based on some calculation.

In this article we will see how to set default values for some common fields using javascript at run time. we will set default values for following type of fields -

Single line of text
Choice
Number
Person or Group
Multiple lines of text
Date and Time
Currency
Yes/No
Hyperlink or Picture

For this we will use task list on team site.Lets add some additional columns in the task list so it can have fields of above types.The Final list design will look like this -

Task Lists
Title - Single line of text
Priority - Choice
Status - Choice
% Complete - Number
Assigned To - Person or Group
Task Group - Person or Group
Description - Multiple lines of text
Start Date - Date and Time
Due Date - Date and Time
Rate - Currency
Check - Yes/No
Link url - Hyperlink or Picture
Picture - Hyperlink or Picture

To accomplish this , open new item page (newform.aspx) in edit view by using toolpaneview=2 query string -
http://server/Lists/Tasks/NewForm.aspx?toolpaneview=2

Now add a CEWP (content Editor WebPart) in this page.We will put all the javascript code in this web part.Open Source Editor and paste following code -


<script type="text/javascript">

// Call SetDefault() function on page load
_spBodyOnLoadFunctionNames.push("SetDefault");

function SetDefault()
{
var peopleValue = GetCurrentUser();
if (peopleValue != null)
SetDefaultValue('PersonGroup','Assigned To',peopleValue);
SetDefaultValue('SingleLineText','Title','My default single Line Text'); SetDefaultValue('Choice','Priority',2);
SetDefaultValue('Choice','Status',3);
SetDefaultValue('Number','% Complete',95);
SetDefaultValue('MultiLineText','Description','My default multi Line Text');
SetDefaultValue('DateTime','Due Date','12/20/2009');
SetDefaultValue('Currency','Rate',452);
SetDefaultValue('YesNo','Check',false);
SetDefaultValue('PictureHyperlink','Link url','http://dpwss:6666/Dev','home site url');
SetDefaultValue('PictureHyperlink','Picture','http://dpwss:6666/_layouts/images/logo.gif','home site logo');

}


//params -
//fieldType - Constant for field type
//fieldLabel - Display Label (name) for the field in list form(new/edit)
//fieldValue - field value to be set in the control
//fieldDescription - Only applicable for 'PictureHyperlink' field

function SetDefaultValue(fieldType,fieldLabel,fieldValue,fieldDescription)
{
var tr = GetFieldRow(fieldLabel);
var controls;
if (fieldType == 'MultiLineText')
{
controls = tr.getElementsByTagName("textarea");
for(var k=0; k < controls.length; k++)
{
if(controls[k].title == fieldLabel)
{
controls[k].innerHTML = fieldValue; break;
}
}
}
else if (fieldType == 'Choice')
{
controls = tr.getElementsByTagName("select");
for(var k=0; k < controls.length; k++)
{
if(controls[k].title == fieldLabel)
{
controls[k].selectedIndex = fieldValue; break;
}
}
}
else if (fieldType == 'PersonGroup')
{
controls = tr.getElementsByTagName("DIV");
for(var k=0; k < controls.length; k++)
{
if(controls[k].id.indexOf("UserField_upLevelDiv") > 0)
{
controls[k].innerHTML = fieldValue;
break;
}
}
}
else
{
controls = tr.getElementsByTagName("input");
for(var k=0; k < controls.length; k++)
{
if (fieldType == 'PictureHyperlink')
{
if(controls[k].title == fieldLabel)
{
controls[k].value = fieldValue;
}
if(controls[k].title == "Description")
{
controls[k].value = fieldDescription;
}
}
else if (fieldType == 'YesNo')
{
if(controls[k].type == "checkbox")
{
controls[k].checked = fieldValue;
}
}
else
{
if(controls[k].title == fieldLabel)
{
controls[k].value = fieldValue;
}
}
}
}
}


//Get control row in the rendered html

function GetFieldRow(fieldLabel)
{
var nobrs = document.getElementsByTagName("nobr");
for(var i=0; i < nobrs.length ; i++)
{
if (nobrs[i].innerText == fieldLabel)
{
var tr = GetParentByTagName("TR", nobrs[i]);
return tr;
}
}
}

//Get parent node
function GetParentByTagName(parentTagName, childElementObj)
{
var parent = childElementObj.parentNode;
while(parent.tagName.toLowerCase() != parentTagName.toLowerCase())
{
parent = parent.parentNode;
}
return parent;
}

//get current Logged In user
function GetCurrentUser()
{
var currentUser;
var tags = document.getElementsByTagName('a');
for (var i=0; i < tags.length; i++)
{
if(tags[i].innerText.substr(0,7) == 'Welcome')
{
currentUser = tags[i].innerText.substr(8,tags[i].innerText.length);
}
}
return currentUser;
}
</script>


More - Client-Side Programming in Sharepoint

Monday, October 26, 2009

Client-Side Programming in Sharepoint # 2

Get All User Collection From Web using javascript


In this article we will see how we can call sharepoint webservices using javascript.Sharepoint provide a webservice usergroup.asmx for user related operations.with the help of xslt , we can show the data retruned by webservice.Following are the steps-
  • Add a content editor webpart on your page
  • Open SOurce editor
  • Add a div element which will show the result
    <div id="results"></div>

  • Add following style element
    <style>
    .resulttable { margin-left:5px; margin-top:3px; padding-top:0px; }
    .heading { font-weight:bold; }
    .admintd { font-weight: bold; color: #009900; }
    </style>

  • Add following javascript code in source editor

    <script type="text/javascript">

    //declare a variable which will hold xslt code

    var _xslText = '&lt;?xml version="1.0" ?&gt;' +
    '&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:response="http://schemas.microsoft.com/sharepoint/soap/directory/"&gt;' +
    ' &lt;xsl:template match="/"&gt;' +
    ' &lt;table class="resulttable"&gt;' +
    ' &lt;th class="heading"&gt;' +
    ' &lt;td class="heading"&gt;Name&lt;/td&gt;' +
    ' &lt;td class="heading"&gt;Login&lt;/td&gt;' +
    ' &lt;td class="heading"&gt;Email&lt;/td&gt;' +
    ' &lt;/th&gt;' +
    ' &lt;xsl:apply-templates select="//response:Users" /&gt;' +
    ' &lt;/table&gt; &lt;div class="ms-vb"&gt;Site administrators are &lt;span class="admintd"&gt;highlighted&lt;/span&gt;.&lt;/div&gt;' +
    ' &lt;/xsl:template&gt;' +
    ' &lt;xsl:template match="//response:Users"&gt;' +
    ' &lt;xsl:for-each select="response:User"&gt;' +
    ' &lt;tr&gt;' +
    ' &lt;td&gt;&lt;/td&gt;' +
    ' &lt;td&gt;' +
    ' &lt;xsl:choose&gt;' +
    ' &lt;xsl:when test="@IsSiteAdmin=\'True\'"&gt;' +
    ' &lt;xsl:attribute name="class"&gt;admintd&lt;/xsl:attribute&gt;' +
    ' &lt;/xsl:when&gt;' +
    ' &lt;xsl:otherwise&gt;' +
    ' &lt;xsl:attribute name="class"&gt;&lt;/xsl:attribute&gt;' +
    ' &lt;/xsl:otherwise&gt;' +
    ' &lt;/xsl:choose&gt;' +
    ' &lt;xsl:value-of select="@Name"/&gt;' +
    ' &lt;/td&gt;' +
    ' &lt;td class="userlistvalue"&gt;' +
    ' &lt;xsl:value-of select="@LoginName"/&gt;' +
    ' &lt;/td&gt;' +
    ' &lt;td class="userlistvalue"&gt;' +
    ' &lt;xsl:if test="@Email!=\'\'"&gt;' +
    ' &lt;a&gt;' +
    ' &lt;xsl:attribute name="href"&gt;' +
    ' mailto:&lt;xsl:value-of select="@Email"/&gt;' +
    ' &lt;/xsl:attribute&gt;' +
    ' &lt;xsl:value-of select="@Email"/&gt;' +
    ' &lt;/a&gt;' +
    ' &lt;/xsl:if&gt;' +
    ' &lt;/td&gt;' +
    ' &lt;/tr&gt;' +
    ' &lt;/xsl:for-each&gt;' +
    ' &lt;/xsl:template&gt;' +
    '&lt;/xsl:stylesheet&gt;';


    var _feedUrl = 'http://server-test/_vti_bin/usergroup.asmx?op=GetAllUserCollectionFromWeb';
    var httpObject = false;
    if (window.XMLHttpRequest)
    {
    try
    {
    httpObject = new XMLHttpRequest();
    }
    catch(e)
    {
    httpObject = false;
    }
    }
    else if (window.ActiveXObject)
    {
    try
    {
    httpObject = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch(e)
    {
    try
    {
    httpObject = new ActiveXObject("Microsoft.XMLHTTP");
    }
    catch(e)
    {
    httpObject = false;
    }
    }
    }

    if (httpObject)
    {
    //Prepare the SOAP request string
    var SOAPBody = '<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><GetAllUserCollectionFromWeb xmlns="http://schemas.microsoft.com/sharepoint/soap/directory/" /></soap:Body></soap:Envelope>';

    httpObject.onreadystatechange = function() { DisplayFeed(); };
    httpObject.open("POST", _feedUrl, true);
    httpObject.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
    httpObject.setRequestHeader("Content-Length", SOAPBody.length);
    httpObject.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/sharepoint/soap/directory/GetAllUserCollectionFromWeb");
    httpObject.send(SOAPBody);
    }



    function DisplayFeed()
    {
    if (httpObject.readyState == 4 && httpObject.status == 200 && httpObject.responseXML)
    {
    var xmlText = httpObject.responseText
    var el = document.getElementById('results');
    if (!el)
    {
    alert('display div missing');
    }
    else
    {
    if (window.ActiveXObject)
    {
    var xml = new ActiveXObject("Msxml2.DOMDocument");
    xml.loadXML(xmlText);

    var xsl = new ActiveXObject("Msxml2.DOMDocument");
    xsl.loadXML(_xslText.replace(/&lt;/g, '<').replace(/&gt;/g, '>'));

    el.innerHTML = xml.transformNode(xsl);
    }
    else
    {
    el.innerText = xml;
    }
    }
    }
    }
    </script>




More - Client-Side Programming in Sharepoint

Friday, September 25, 2009

Client-Side Programming in Sharepoint # 1

When an asp.net developer start exploring SharePoint, the very basic question they have in mind is how can we do something at client side in SharePoint or where can we embed JavaScript or jquery script in SharePoint page. SharePoint provide us the freedom to add our scripting in following places-
  • Add a Content Editor Web part on the page , and add your script in source editor
  • Open page in SPD (SharePoint Designer) and embed your script on html source.
  • Add your script in source code of custom page/web part/.. .
  • Add custom JavaScript file and override existing JavaScript function from core.js file.
  • Etc.

In this series I will try to cover some of the task possible at client side in any SharePoint application ,as well as will give reference to some nice articles available on this topic.Here are some of my posts on this,




More - Client-Side Programming in Sharepoint