Monday 9 December 2013

WebStorage in HTML5

In this module I am going to discuss Web Storage in HTML5

What Is Web Storage?
With HTML5 web storage, websites can store data on a users local computer

Now No More Cookies concept in HTML5
We had to use Javascript cookies in the past to achieve this functionality.

How It Differs From Cookies
·         More secure
·         Faster
·         Stores a larger amount of data
·         The stored data is not sent with every server request. It only is included when asked for. This gives a big advantage over cookies

Detecting HTML5 Storage Support
function supports_html5_storage() {
       try {
          return 'localStorage' in window && window['localStorage'] !== null;
        } catch (e) { 
               return false;
        }
}
With Modernizr (Recommended):
if (Modernizr.localstorage) {
        // Local storage available
} else {
       // No local storage available
}

localStorage( ) & sessionStorage()
There are 2 types of web storage objects, local and session
Difference:
localStorage – Stores data with no expiration date
How It Works
sessionStorage – Stores data for one session
The localStorage and sessionStorage objects create a key = value pair
Example: key=“Name”, value=“Bob”
They are stored as strings but can be converted after if needed by using JS functions like parseInt() and parseFloat()

Syntax for Web Storage
1)   Storing a Value:
localStorage.setItem("key1", "value1");             object
localStorage["key1"] = "value1";                          array
2)   Getting a Value:
alert(localStorage.getItem("key1"));  
alert(localStorage["key1"]);  
3)   Remove a Value:
removeItem("key1");  
Remove All Values:
localStorage.clear();

Monday 2 December 2013

Introduction to HTML5

Now we are going to see what is HTML5, what is the need of expanding HTML, what are the new features in HTML5 and  etc. concepts.

What is HTML5?
HTML5 will be new standard
HTML5 is a cooperation between the W3C (world wide web consortium) and (web hypertext application technology working group (WHATWG)
HTML5 Offers some great features that I will make the web more dynamic.

New Features:
·         New sets of tags such as <header> and <section>
·         <canvas> element for 2d drawing
·         Local storage ex cookies and small amount of data
·         New form control like calendar,date and time
·         New media functionality
·         Geolocation

Expanding HTML
One of the biggest reasons for HTML5 is to prevent users from needing to download and install multiple plugins such as Flash and Silverlight.

HTML5 Stack:
·         HTML5
·         CSS3
·         Javascript

New Form Elements
New Input types 
Ex: color, rage, seach, datatime, tel, datetime-local, time, email, url, month, week, number etc

·         Email:  input type allows the form to validate the email address format without using javascript
<input type=”email” name=”email”>
·         Color : Allows to you color from the picker
<input type=”color” name”favcolor”>
·         Date: Allows user to select a date
<input type=”date” name=”bDate”>
·         Range: Gives us a control for entering a number whose exact value is not important  (like  slider control)
<input type=”range” name “points” min=”1” ma=”10”>
·         Tel: Used to define a field for entering telephone number
<input type=”tel” name=”usrtel”>
·         Time: Used to define a field for entering a time
<input type=”time” name=”usr_time”>
·         URL: Used to define a field for entering a url/link
<input type=”url” name=”homepage”>

Datalist:
Specifies a list of predefined options for an <input> element.
Provides an “autocomplete” feature on <input> elements. Users will see drop-down list of pre-defined options as they input data.
Use the <input> element’s list attribute to bind it together with a <datalist> element.
<input list="browsers">
<datalist id="browsers">
                   <option value="Internet Explorer">
                   <option value="Firefox">
                   <option value="Chrome">
                   <option value="Opera">
                   <option value="Safari">
          </datalist>


<keygen>
·         Provides a secure way to communicate users.
·         The <keygen> tag specifies a key-pay generator field in a form.
·         When the form is submitted, two keys are generated, one private and another one public.
·         The private key is stored locally, and the public key is sent to server. The public key could be used to generate a client certificate to authenticate the user in the future.

<output>
Perform calculation and show the result in an <output> element:


Tip
What happens if you view a new HTML5 form input type in an older browser?

It reverts to a standard text input

Saturday 30 November 2013

Choosing Migration VS. Upgrade



1.     When
Ø When upgrade is not possible due to bad prior choices
·        Database Modifications
·        Unsupported site definitions
Ø When downtime is not tolerable

2.     Why
Ø    Cost of downtime is higher than negative impact from migration
Ø    Massive redesign is required to site/data structures

3.     How
Ø Migrate using 3rd party tools only, no Microsoft supplied solution.

Thursday 5 September 2013

Search Query APIs in SharePoint 2013

To develop the custom solution types for the search results, SharePoint 2013 Provides several query APIs for search and giving us lots of ways to access the search results.

SharePoint 2013 provides the following in addition to Server Object Model which was available in previous versions.

Clicent Object Model(CSOM)
JavaScript Object Model (JSOM)
Representational State Transfer (REST) Service.

API Name
Class library or schema and path
.NET CSOM
Microsoft.SharePoint.Client.Search.dll
%ProgramFiles%\Common Files\Microsoft Shared\web server extensions\15\ISAPI
Silverlight CSOM
Microsoft.SharePoint.Client.Search.Silverlight.dll
%ProgramFiles%\Common Files\Microsoft Shared\web server extensions\15\TEMPLATE\LAYOUTS\ClientBin
JavaScript CSOM
SP.search.js
%ProgramFiles%\Common Files\Microsoft Shared\web server extensions\15\TEMPLATE\LAYOUTS
REST service endpoints
http://server/_api/search/query
http://server/_api/search/suggest
Server object model
Microsoft.Office.Server.Search.dll
%ProgramFiles%\Common Files\Microsoft Shared\web server extensions\15\ISAPI

Using Client APIs is one of the best practices in SharePoint 2013 when you can. Client APIs include the .NET, Silverlight, Phone, and JavaScript client object models, and the REST service. 


1) Query using the .NET Client Object Model

This enable to access search results for online, on – premises and development. The search in SharePoint 2013 CSOM is built on the SharePoint 2013 CSOM.

For the .NET managed CSOM, get a ClientContext instance (located in the Microsoft.SharePoint.Client namespace in the Microsoft.SharePoint.Client.dll). Then use the object model in theMicrosoft.SharePoint.Search.Client.Query namespace in the Microsoft.SharePoint.Search.Client.dll.

Follow below example.

using (ClientContext _clientContext = new ClientContext("http://<<serverName>>/sites/<<siteCollectionPath>>"))
{
    KeywordQuery _keywordQuery = new KeywordQuery(_clientContext);
    _keywordQuery.QueryText = "SharePoint 2013";
    SearchExecutor _searchExecutor = new SearchExecutor(_clientContext);
    ClientResult<ResultTableCollection> _results = _searchExecutor.ExecuteQuery(_keywordQuery);
    _clientContext.ExecuteQuery();
}


2) Query using the JavaScript client object model

First we need to get a ClientContext instance, and then use the object model in the SP.Search.js file.

Here's a basic example.
var _clientContext = new SP.ClientContext("<<serverRelativeUrl>>");
var _contextSite = _clientContext.get_site();
var _keywordQuery = new Microsoft.SharePoint.Client.Search.Query.KeywordQuery(_clientContext); 
_keywordQuery.set_queryText("SharePoint2013"); 
var _searchExecutor = new Microsoft.SharePoint.Client.Search.Query.SearchExecutor(_clientContext);  
var _results = _searchExecutor.executeQuery(_keywordQuery); 
context.executeQueryAsync(onQuerySuccess, onQueryError);
 
3) Query using the REST service

SharePoint 2013 includes a REST service that enables you to remotely execute queries against the SharePoint 2013 Search service from client applications by using any technology that supports REST web requests. The Search REST service exposes two endpoints, query and suggest, and will support both GET and POST operations. Results are returned in either XML or JavaScript Object Notation (JSON) format.
The following is the access point for the service: http://<<server>>/_api/search/. You can also specify the site in the URL, as follows: http://<<server>>/site/_api/search/. The search service returns results from the entire site collection, so the same results are returned for both ways to access the service.


4) Query using the .NET server object model

Applications that use the server object model must run directly on a server that is running SharePoint 2013. The search Query server object model resides in the Microsoft.Office.Server.Search.Querynamespace, which is located in Microsoft.Office.Server.Search.dll.
As in SharePoint Server 2010, you use the KeywordQuery class to define the query, and then called the Execute() method to submit the query. In SharePoint 2013, the Execute method is obsolete, and while it will still work, you should use the SearchExecutor class instead. To submit the query, call the ExecuteQuery() method, passing the instance of the KeywordQuery class in the call.

Follow below example.

using (SPSite _siteCollection = new SPSite("<serverRelativeUrl>")) 
{
    KeywordQuery _keywordQuery = new KeywordQuery(_siteCollection);
    _keywordQuery.QueryText = "SharePoint2013";
    SearchExecutor _searchExecutor = new SearchExecutor(); 
    ResultTableCollection _resultTableCollection = _searchExecutor.ExecuteQuery(_keywordQuery); 
    _resultTableCollection = _resultTableCollection.Filter("TableType", KnownTableTypes.RelevantResults); 
    ResultTable _resultTable = _resultTableCollection.FirstOrDefault(); 
    DataTable dataTable = _resultTable.Table; 
}