Showing posts with label Client Object Model. JSOM. Show all posts
Wednesday, February 4, 2015
Get Site Name using ECMAScript very quickly and easily
Posted by
Santhosh,
on
6:18 AM
Hi Friends ,
Thanks for Visiting my blog.
In my previous post , I was described about ECMAScript Client Object Model.
In this Post ,I would like to describe How we can get the Site Title through ECMAScript ?.
Please find the below steps to achieve this Site Title .
1. Open Visual Studio -->Create an Empty Project (Farm Solution) -->Create Visual web Part
2. Add the below script files refernces in UserControl.ascx
<Script src="//code.jquery.com/jquery-1.10.2.js"></script>
<SharePoint:ScriptLink ID="ScriptLink1" Name="SP.js" runat="server" OnDemand="true"
Localizable="false" />
3. Add the Below Script UserControl.ascx
<script type="text/ecmascript">
function getWebProperties() {
var ctx = new SP.ClientContext.get_current();
this.web = ctx.get_web();
ctx.load(this.web);
ctx.executeQueryAsync(Function.createDelegate(this, this.onSuccess),
Function.createDelegate(this, this.onFail));
}
function onSuccess(sender, args) {
alert('web title:' + this.web.get_title());
}
function onFail(sender, args) {
alert('failed to get list. Error:' + args.get_message());
}
</script>
Below is the Screen Shot of Visual Web part after we done with Scripting inside the ascx.
5. Navigate to the SharePoint Site in which you want Place the Web Part .
6. Add Web Part in your Page and click on the button . You will be able to see the Web Site Title .
This is how , we get the Site Name very easily using ECMAScript with minimal Scripting.
Description about Script
1. var ctx = new SP.ClientContext.get_current();
Getting the Current Site Collection Context
2. this.web = ctx.get_web();
Getting the Current Web Context.
3. ctx.executeQueryAsync(Function.createDelegate(this, this.onSuccess),
Function.createDelegate(this, this.onFail));
executeQueryAsync
Executes the current pending request asynchronously on the server.
The executeQueryAsync method is inherited from the SP.ClientRuntimeContext object. This virtual method is asynchronous, which means that the code will continue to be executed without waiting for the server to respond.
onSuccess
A function or a delegate of the method to call if the request executes successfully.
onFail
A function or a delegate of the method to call if the request fails to execute.
Hope this post is useful...
Thanks
Wednesday, November 26, 2014
Working with the ECMAScript Client Object Model (JSOM) in SharePoint 2013,2010
Posted by
Santhosh,
on
11:27 PM
Thanks for visiting to my blog .
Today am going to explain about ECMAScript Client Object Model (JSOM) in SharePoint 2013,2010
ECMAScript :
ECMAScript is a java script based client side scripting language which is now supported in SharePoint 2010 and can be used to access Client Object Model.
Background
One of the coolest features of SharePoint 2010 and 2013 as well. You might already know that if we have to talk to SharePoint 2007 and don’t want to write the server side code then we call SharePoint Web Services. Now with SharePoint 2010 we can use Client Object Model to talk to SharePoint and the option of web services is still there. Once a wise man said, two options are always better than one.
- SharePoint Client Managed Object Model is a SharePoint API that runs on the client side.
- It converts the API calls made by the application, into XML request and sends it to the SharePoint server. On the server, the XML request is handled by a service called Client.svc where it translates the XML request in to appropriate Object Model calls (SharePoint Server Object Model) and gets the results.
- After getting the results, Client.svc translates them into JavaScript Object Notation (JSON) and sends back to the Client Managed Object Model. On the client side the JSON response is translated into ECMAScript objects for ECMAScript.
This is just a breif description of our ECMA Script . In our next articles we will see the examples of ECMAScript.
Subscribe to:
Posts
(
Atom
)