Oct 22
Using SharePoint 2013 Term Store to create Navigation

One of the new features in SharePoint 2013 is the ability to use the Term Store to use navigation.

What is Managed Navigation?

In SharePoint, you can choose between two navigation methods: structural navigation or managed navigation. Structural navigation is based on site structure. Managed navigation is based on term sets.

Managed navigation lets you define and maintain your site navigation by using term sets. With managed navigation, it's not the location of your content that defines where in the navigation your content will appear, but how you tag your content with terms from a term set. For example, in previous versions of SharePoint, if you wanted to add a new page under "About Us," you had to add that page under the "About Us" branch within your content. With managed navigation, you can add a page to the branch that makes the most sense to you. By tagging that page with a term, and using Search Web Parts, it will appear in the correct place in the navigation.

Managed navigation creates friendly URLs. In previous versions of SharePoint, the URL to a page contained a reference to the Pages library and any folders within that library, for example: http://www.sharepointempower.com/Pages/About-us.aspx. With managed navigation, URLs are based on the terms in the term set that drives your site navigation, for example:http http://www.sharepointempower.com/Pages/About-us.

In a cross-site publishing scenario, it is quite common for the publishing site to use managed navigation.

 

We have below Term set to create Multilevel Navigation within our site. Here we have created a Term Set structure to use as Navigation.

 

Currently without Top Navigation, The site is looking like this:


We can now enable the Term Store driven navigation for this site by going under Site Settings –> Navigation and selecting "Managed Navigation" for either the global navigation (the top navigation) or the current navigation (the left navigation).   Let's do this for the global navigation for this site:

Here, In the Global Navigation select Managed Navigation option and in Managed Navigation: Term Set option select the Term Set which you want to use as Navigation. Here I have selected Top Navigation Term set and then click on Ok to apply your changes.

So once applied now you can see the Top Navigation is now coming from Managed Metadata.


The above is a Global Navigation (the Top Navigation). Same way we can apply Managed Metadata for current navigation (the left navigation) as well.

Go to Site Settings -> Navigation,

Here, In the Current Navigation select Managed Navigation option and in Managed Navigation: Term Set option select the Term Set which you want to use as Navigation. Here I have selected Top Navigation Term set and then click on Ok to apply your changes.


Once applied this you can see now the Managed Metadata Navigation is applied to Left Navigation.


 

There are two features enabled by the checkboxes below the term store:

  • Add new pages to navigation automatically: if this item is checked, SharePoint 2013 automatically creates terms in your term set every time you create a new page.
  • Create friendly URLs for new pages automatically: if this item is checked, SharePoint 2013 will use your term store to create friendly URLs based on your terms.

With these enabled, it allows you to very quickly generate a site navigation and the associated pages based on your term set hierarchy.

 

As you can see, the term store is hierarchical, which automatically creates hierarchical navigation for the global navigation.

Oct 14
SharePoint Rest API – Using JQuery Deferred Object

 

To communicate with SharePoint, developers sometimes may want to use SharePoint Rest API for better speed and performance.

 

The SharePoint Rest API can be used by inheriting the SP.RequestExecutor.js which available at the ".../_layout/15/".

 

In some cases, there will be need of where one asynchronous call is dependent upon another call's output. For that we will need to control the calls sequences. But as we all know the fact that JavaScript is asynchronous and the flow of asynchronous calls cannot be controlled.

 

Well, here comes the JQuery Deferred Object in the picture…

 

The JQuery Deferred object maintains an asynchronous call and it returns a Promise object when the call is complete.

 

The Promise object has two main methods to use,

  1. done(fnSuccess, fnError, fnInProgress)
  2. then(fnSucess)

 

For more information on JQuery Deferred object see the article of JQuery Deferred Object Documentation à https://api.jquery.com/jquery.deferred/

 

We have created a small example of using JQuery Deferred object as shown below,

 

 

functionToCall().done(function (returnedValue) {

// do something with the returned value

    // or make another call here

});

 

function functionToCall() {

 

var dfd = new $.Deferred();

    

    var executor;

    executor = new SP.RequestExecutor(appweburl);

    executor.executeAsync({

        url: queryUrl,

        method: "GET",

        headers: {"Accept": "application/json; odata=verbose"},

        success: onSuccess,

        error: onError

    });

 

function onSuccess(data){

        var myVar = data.d.results;    

        dfd.resolve(myVar);

    }

 

    function onError(data, errorCode, errorMessage){

        dfd.reject('Failed to load due to : '+errorMessage);

    }

 

return dfd.promise();

}

 

 

Some Notes to keep: -

  1. Make sure the success and error handler are inside the async function so that the deferred object (dfd) remains global to them.
  2. Both success and error handler should have deferred resolve and deferred reject methods.

 

SharePoint JSOM – Using JQuery Deferred Object

 

Sometimes developers also stumbles upon using Client Context in JavaScript which is also asynchronous.

To use client context in the JavaScript you need to inherit MicrosoftAjax.js, sp.runtime.js & sp.js from "…/_layouts/15/".

JQuery Deferred object can be used here too to make things simple, we have created a small example for that too.

 

  functionToCall().done(function (returnedValue) {

// do something with the returned value

});

​ function functionToCall() {

               var dfd = $.Deferred(function () {

  var valueToReturn = clientContext.get_web();

               clientContext.load(valueToReturn);

               clientContext.executeQueryAsync(function () {

               dfd.resolve(valueToReturn);

         },

         function (sender, args) {

                //throw an error

         });

   });

 return dfd.promise();

 }

​Hope this helps J

 

Thank you for reading the post J

Jun 15
How to get Simple Link Url Property of Taxonomy Term using JSOM in SharePoint 2013

Alright so, i was doing some Research and Development on

How to get Simple Link Url Property of Taxonomy Term using JSOM in SharePoint 2013

of a taxonomy navigation term from code-behind. I found that there were very few posts and some of them even had mistakes in their code snippets so i decided to make a blog and share correct information to you guys :) 

 

Now if you don't know how to create a Navigation term, here are some steps you'll need to go through.

 

1) First open up your taxonomy term store from the SharePoint Site Settings > Term Store Management.

 

2) create a demo Term-Set Group and Then a demo Term Set in the Term Store.

 

3) Now, go to the Demo Term-Set you've just created, you'll find "Intended Use" menu item. Click on it and you'll see below page.




 

4). Now select "Use this Term Set for Site Navigation" and press Save

 

Alright, so you're now ready to create some navigation terms, i have created some navigation terms as per below pictures and now we will see how to set the Simple Link Url property of a term and get it from code-behind (JSOM).

 

1). Select any term that you have created, go into "Navigation" menu. 




2). Going to "Navigation" will look like as below picture, select "Simple Link or Header", and write down your Url or you can browse it from your existing site.




3). Now to get this URL from Code, there is only one line you will have to write (Which is highlighted in my code snippet), 

______________________________________________________________

 

context = new SP.ClientContext.get_current();

      

    var taxSession = SP.Taxonomy.TaxonomySession.getTaxonomySession(contextsidebar);

    //Term Stores

    var termStores = taxSession.get_termStores();

    //Name of the Term Store from which to get the Terms.

    var termStore = termStores.getByName("Taxonomy_3NhjDrbwzBe+Q+8TIIafFw==");

      

    //GUID of Term Set from which to get the Terms.

    var termSet = termStore.getTermSet("96a82fb7-dd1c-41d4-8223-c118f7ab52f8");

 

    var terms = termSet.get_terms();

    context .load(terms);

 

    context .executeQueryAsync(function () {

 

        var termEnumerator = terms.getEnumerator();

        //ToptermList = $('#sidebarUl');

        var mainul = $('#mainUL');

 

        while (termEnumerator.moveNext()) {

 

            var currentTerm = termEnumerator.get_current();

              

            termName = currentTerm.get_name();

            termId = currentTerm.get_id();

            var simpleLinkUrl = currentTerm.get_localCustomProperties()._Sys_Nav_SimpleLinkUrl;

                         

            if (currentTerm.get_termsCount() > 0) {

                //Term has sub terms.                       

            }

        }

        //alert(termList);

    }, function (sender, args) {

        // console.log(args.get_message());

    });

}

______________________________________________________________

​Here are some more properties you can get by replacing the names in the code,

 

  • _Sys_Nav_Title: the Navigation Node Title
  • _Sys_Nav_FriendlyUrlSegment: the Friendly Url, also represented by the FriendlyUrlSegment property of theNavigationTerm class.
  • _Sys_Nav_TargetUrl: the target URL, also represented by the TargetUrl property of the NavigationTermclass.
  • _Sys_Nav_TargetUrlForChildTerms: the target URL for child terms, also represented by the TargetUrlForChildTerms property of the NavigationTerm class.
  • _Sys_Nav_CatalogTargetUrl: the catalog target URL, also represented by the CatalogTargetUrl property of theNavigationTerm class.
  • _Sys_Nav_CatalogTargetUrlForChildTerms: the catalog target URL for child terms, also represented by the CatalogTargetUrlForChildTerms property of the NavigationTerm class.

 

For Updating the Terms Navigation Custom Properties:

The Key to understand, by executing the SetLocalCustomProperty method on the_Sys_Nav_Title property, I was able to set the Navigation Node Title:

term.SetLocalCustomProperty("_Sys_Nav_Title", "myLocation");

If you use that same method with a property name that does not exist, it will create a custom property (which is then visible on the Custom Properties tab); just like the SetCustomProperty method does.

Save your changes to the term store when you're finished:

termStore.CommitAll();

 

 

There will be some circumstances that you'll need to get this Url from Code-behind, otherwise you can also use SharePoint Managed Site Navigation provides great In-Built functionality to create top-menu using Navigation Term Set.

 ​

Hope this helps :)

Jan 08
Using the People Picker control in Sandbox solution / Office 365

 

The SharePoint sandbox does not allow you to use the Microsoft.SharePoint.WebControls namespace in your code. This means you can't instantiate objects from classes in that namespace or automate existing object instances of classes in that namespace.

SharePoint 2013 has a changed the usability and functionality of a people picker. Also it enabled client side programming to search for users across Active Directory. So you can use Client Side People Picker Control in Sandbox Solution as well.

In this blog we will see how to create Clien​t Side People Picker Control in S​harePoint 2013 Sandbox solution.

 

Step 1: Now Open Visual Studio and create a Visual Web Part for that. First click on New Project.

 

Step 2: Now from Template -> Visual C# -> Office/SharePoint, select SharePoint 2013 Visual Web Part. Give it a name PeoplePicker and click Ok.

 

Step 3: Now in What site do you want to use for debugging? , give the url of the site and in What is the trust level for this SharePoint Solution? , select Deploy as Sandboxed solution and click on Finish.

 

Step 4: Now right click the solution and click on Add, and click New Item.

 

Step 5: From Visual C# Items -> Office/SharePoint, select Visual Web Part and give it a name PeoplePickerControl and click on Add to add new Visual Web Part to the solution.

 

Step 6: Now right click the solution click on Add and click on New Item.

 

Step 7: From Visual C# Items -> Office/SharePoint, select Module and give it a name as PeoplePickerModule and click Add. There may be times when you may want to deploy files to the SharePoint server regardless of their file type, such as new master pages, js , css etc. To do this, you can use Modules. Modules are containers for files in a SharePoint solution. When the solution is deployed, the files in the module are copied to the specified folders on the SharePoint server.

 

Step 8: Now open the Element.xml file of the module. You can see there is no reference given in that file where it will add the module after deployment.

 

Step 9: Now add the url property in the <Module></Module> tag to Style Library , so it will be added to style library after deployment.

 

Step 10: Now right click the module and click Add and click on New Folder to create js folder.

 

 

Step 11: Now add jquery-1.9.1.min.js and sppeoplepicker.min.js in js folder.

 

 

Step 12: Now add the JQuery reference in the web part.

 

Step 13: Now In the document.ready function register the people picker for the div elements.

 

Step 14: Here is the html template for the example.

 

Step 15: Now build the solution by right clicking the solution and click on Build.

 

Step 16: Now deploy the solution. Right click the solution and click on Deploy.

 

Step 17: Now create a page. Go to Site Pages -> Files and select Web Part Page, to create web part page.

 

Step 18: Here give page a name say PeoplePicker In Name textbox, in Layout select Full Page, Vertical, and in Save Location select Site Pages and click on Create.

 

Step 19: Click on Add a Web Part, select Custom and select the custom web part, here PeoplePickerControl and click Add to add that web part to the page.

 

Step 20: After adding that web part to the page, can be used as People Picker control. User can write the name of the user and it will find the user from the site and work as People Picker in the Sand box solution as well.



You can Download the source code from the below link ->

https://gallery.technet.microsoft.com/sharepoint/People-Picker-Control-in-c00847dd/file/132192/1/PeoplePickerControlInSandboxSolution.zip​

Dec 30
Create Custom Discussion Board App in SharePoint 2013

 

Discussion boards provide forums for site participants to discuss topics with each other. Most site templates include the ability to create discussion boards.

In this blog we will see how to create Custom ​Discussion Board app in SharePoint 2013.

Step 1: To create SharePoint App for Discussion Board, user needs to create Discussion Board list. To create the list go to Site Settings -> Site Contents.

 ​

 

Step 2: from Site Contents click on add an app.

 

 

Step 3: from add an app click on App Details to create new app.

 

Step 4: Now click on ADD IT to create list based on Discussion Board Template.

 

 

Step 5: Here can see the Discussion Board list created.

 

 

Step 6: Now to create SharePoint Hosted App for Discussion Board, first open Visual Studio and click on New Project to create a new project.

 

 

Step 7: From Template -> Visual C# -> Office/SharePoint -> Apps, select Apps for SharePoint and give it a name DiscussionBoardApp and click Ok.

 

 

Step 8: Here in Which SharePoint Site do you want to use for debugging your app?, give your site's url where you want to debug this app and in How do you want to host your app for SharePoint?, select SharePoint-hosted and click Finish.

 

 

Step 9: Here right click the solution and from Add click on New Item.

 

 

Step 10: From Visual C# Items -> Office/SharePoint, Select Client Web Part (Host Web) and give It a name DiscussionBoard and click Add.

 

 

Step 11: Here select the option Create a new app web page for the client web part content, give page a name and click Finish.

 

 

Step 12: After creating a page create a JavaScript to work in app. To create a script go to Scripts -> Add -> New Item.

 

 

 

Step 13: From Visual C# Items -> Web -> JavaScript File and give It a name discussion.js and click Add.

 

 

Step 14: Here in DiscussionBoard.aspx, add reference of JavaScript, css and add the UI part.

 

 

Step 15: Here in Elements.xml file, create custom property. Here user can set the default value for property.

 

 

Step 16: In discussion.js file add your code for Discussion Board. It will have the logic of the app.

 

 

Step 17: In the AppManifest.xml file in the Permissions tab in the scope select Site Collection and in Permission select FullControl.

 

 

Step 18: After completing this, right click the solution and then click on Build to build the solution.

 

 

Step 19: Once solution is build, Deploy the solution by right clicking the solution and click on Deploy.

 

 

 

Step 20: After Deployment will be completed It will ask to Trust the app. Click on Trust It.

 

 

Step 21: Here in the Site Contents user can see the DiscussionBoardApp is deployed.

 

 

Step 22: Now from Settings gear icon, select Add a Page to create new page.

 

 

Step 23: Here give It a name Discussions and click Create to create a new page.

 

 

Step 24: From Edit Page, click on Insert then on App Part and then select DiscussionBoard App part which is created and click on Add.

 

Step 25: After Adding the App in a page It will look like the below one. Here all the discussions which are running will be shown and users can Reply to that discussion and can see all replies by clicking on View all replies link.

 

 

You can Download the source code from the below link ->

https://gallery.technet.microsoft.com/sharepoint/Custom-Discussion-Board-918d8d40/file/132194/1/CustomDiscussionBoardApp.zip​


Nov 12
Create Page Layout in SharePoint 2013

 

In this blog we will see how to create Page Layout in SharePoint 2013.

A Page Layout in SharePoint allows users to create a template for a page that users apply to their content for a consistent layout of Information. Once Layout of Information is defined, a user can choose to create a new page using that layout. Rather than design the page from scratch.

Below are the steps for creating Page Layout in SharePoint 2013:

 

Step 1: From Site Action, go to Site Settings, and in Site Settings from Look and Feel go to Design Manager.

 

Step 2: From Design Manager, select Edit Page Layout.

 

Step 3: From Edit Page Layout, go to Create a Page layout to create a new page Layout.

 

Step 4: Here give the appropriate name to the page Layout in the Name box, select the master page where you want to apply Page Layout in Master Page column and select the Content Type from Content Type column and then click Ok.

 

Step 5: From Design Manager -> Edit Page Layouts, select your page layout.

 

Step 6: Here a new window will open, select Snippets option from there.

 

Step 7: Here select Web Part Zone and copy the code from HTML Snippet given below and then click on Update.

 

Step 8: Now open SharePoint Designer, click on Page Layouts. Here you can see two files, FPCHomePageLayout.aspx and FPCHomePageLayout.html.

 

Step 9: Now Paste the Web Part Zone which was copied from Snippet inside the <Body> tag. Here in this example we have used Slider. So there will be web part zones in slider structure.

 

Step 10: Now from Site Action, click on Add a Page to add new page.

 

Step 11: Give that page any name and click on Create.

 

Step 12: In the Home.aspx page which is created, from Ribbon, click on Page -> Page Layout and then select page layout FPCHomePage which was created earlier and Save the page.

 

Step 13: After adding Page Layout to the page, It will look like the below one.

 

Step 14: The page layout structure which is created here in this example is with a slider. So here u can slide this layout and see the structure of It from the other slide as well.

 

Step 15: Here to add web parts in this page, from Ribbon go to Page->Edit.

 

Step 16: Here you can see there are different zones given which are web part zones created earlier. In each zone there is a link Add a Web Part. By clicking that user can add a web part there.

 

Step 17: After clicking on Add a Web Part link, in Ribbon from Categories, select the category of web part and then select the web part itself and click on Add. After adding web part click on Save to save the page and user can get the web parts they added at the required web part zone.

 

 

 

 

 

Nov 07
Get Quick Launch Navigation in SharePoint 2013 dynamically

In this blog we will see how to get Quick Launch Navigation in SharePoint 2013 dynamically.

Quick Launch can be used to display section headings and links to different areas of your SharePoint site in a logical manner.

On a Microsoft Office SharePoint 2013 site, you can customize the Quick Launch by adding, removing, or reordering, links. You can also hide links to sub sites and pages. You can even add links to pages outside the site.

Note: To manage navigation for a SharePoint site, you must have the Full Control or Design permission level for the site. You have one of these permission levels if you can access the Sites Settings page for the site and you see the Navigation command under Look and Feel (on non-publishing sites, you will see the Quick Launch and Top link bar commands under Look and Feel instead of Navigation).

Sometimes there may be a requirement to show Quick Launch dynamically in a web part or in an App except the Quick Launch placed by default in SharePoint 2013. So here created a Visual Web Part to fetch Quick Launch data in SharePoint 2013 programmatically.

You can get Quick Launch programmatically and using Power Shell.

You can get Quick Launch programmatically and using Power Shell.

 

  • Get Quick Launch Programmatically:

It will fetch the data from Quick Launch and I have given it a structure like accordion.

Step 1: In your site go to Style Library and create one folder called DocLib and then add 2 more folder inside it and give names as css and js respectively.

Step 2: Add stylesheet.css and jquery-ui.css in the css folder and add jquery.accordion.js and jquery-1.10.2.min.js in js folder.

 

Step 3: First open Visual Studio, the click on New Project and after that go to Templates->Visual C#->Office/SharePoint->SharePoint Solutions->SharePoint 2013 Visual Web Part and then give name to that web part. I have given name to DocumentLibrary and then click Ok.

 

Step 4: Now In What site do you want to use for debugging? , add your site url there and in What is the trust level for this SharePoint solution? Select Deploy as a Sandbox solution and click on Finish.

 

Step 5: Now right click the solution and from Add go to New Item.

 

Step 6: Now from Visual C# Items->Office/SharePoint select Visual Web Part and give a name to that. I have given name as DocLib and then click on Add.

Step 7: Now write down the code for getting Quick Launch Programmatically. Here is the code for DocLib.ascx page.

Step 8: Here is a code for DocLib.ascx.cs page.


In the below screen shot by this code we will get the Quick Launch data.

 

Step 9: Now right click the solution and click on Build.

 

Step 10: right click the solution and click on Deploy.

 

Step 11: First create a page and then edit that page. From ribbon click on Web Part and then click on Custom and select the web part DocumentLibrary-DocLib and click ok.

Step 12: Here you can see the Output, which fetches data from Quick Launch Programmatically.

 

You can Download the source code from the below link ->

https://gallery.technet.microsoft.com/sharepoint/Getting-Quick-Launch-1df60c46/file/128392/1/FetchSharePointQuickLaunchData.zip

 

  • Get Quick Launch using Power Shell:

Step1: Open SharePoint 2013 Management Power Shell as Administrator.

Step 2: Write below code in Power Shell Management.

$siteURL="http://serverName:1111/sites/SPSiteDataQuery/"
$site=Get-SPSite $siteURL
$web=$site.RootWeb
$navigationNodeColl=$web.Navigation.QuickLaunch
foreach($heading in $navigationNodeColl)
{
write-host -f Green $heading.Title
foreach($links in $heading.Children)
{
write-host -f Yellow $links.Title
}
}

The code is shown in the below fig:

 

Step 3: We will get Quick Launch as the output using Power Shell.

 

Jul 23
Restore a deleted Site Collection in SharePoint 2013

In this blog we will see How to restore a deleted Site Collection from SharePoint 2013 On Premise and SharePoint 2013 Online.

 

Restore Site Collection in SharePoint 2013 On Premise

If you are using Office 365 then it's all through the admin interface for SharePoint. Under the section where you manage your site collections there is a recycle bin icon on the ribbon, go to Recycle Bin and restore it.

If you have SharePoint on-Premise fire up PowerShell on the server. Make sure it's either the Management shell or you have the SharePoint modules loaded.

 

Here is an example of How to restore a deleted Site Collection in SharePoint 2013 On Premise.

 

Step 1: Go to Central Administration -> Application Management, in Application Management from Site Collection go to View All Site Collections. Here you can see all the site collection for each Web Applications.

 

 

 

Step 2: Here to show how to Restore Site Collection using Power Shell, I have created a Site Collection named sample site in a Web Application.

 

 

 

Step 3: Now If That Site Collection will be deleted then we can restore it using PowerShell. Here is a list where you can see that the sample site collection which I created is now not there because it is deleted.

 

 

 

You can restore your deleted Site Collection from SharePoint Farm using Powers-shell.

 

Step 4: Get Deleted Site Collections. Open SharePoint PowerShell and Type following 

  Get-SPDeletedSite

  It will Return Deleted Site collections.

 

 


Step 5: Now write command for Restore Deleted Site Collections.

 Restore-SPDeletedSite -Identity SiteID-From-Above-Screen

 After Pressing Enter it will ask for confirmation. Press Y and Proceed.

 

 


Step 6: Now after writing this commands in SharePoint 2013 Management Shell the Site Collection will again be restored. You can see that in below screen:



				

  


Restore Site Collection in SharePoint 2013 Online

 

The Recycle Bin in SharePoint Online for Enterprises provides a safety net when an entire site collection is deleted. When a SharePoint Online administrator deletes a site collection, it is placed in the Recycle Bin, where it is kept for 90 days before it is automatically permanently deleted.

This blog is about on how a SharePoint Online administrator can restore a deleted site collection.

As a SharePoint Online Administrator, you can view and manage deleted site collections from the SharePoint Online Administration Center Recycle Bin page. You can view site collections that are currently in the Recycle Bin, see how many days are left before the site collection is permanently deleted, and restore a deleted site collection without contacting Microsoft Support.

To permanently delete a site collection after it has been placed in the Recycle Bin, you don't need to take any additional action; it is automatically removed from the Recycle Bin after 90 days. You can restore a deleted site collection if you have met all of the following conditions:


  • The site collection has been in the Recycle Bin no longer than 90 days.​​
  • The usage quota for your SharePoint Online tenant has not been exceeded.
  • The storage quota for your SharePoint Online tenant has not been exceeded.

If you try to create a new site collection that uses the same URL as a site collection that is in the Recycle Bin, you will be prompted to permanently delete the site collection in the Recycle Bin before you can proceed.

 

Here is the example of How to restore deleted Site Collections using Recycle Bin in SharePoint 2013 Online.

View deleted site collections by using Recycle Bin page

 

Step 1: Navigate to the SharePoint Online Administration Center page and click Site Collection.

 

 

 

Step 2: On the ribbon, click Recycle Bin.

 

 

 ​

Step 3: Here you can see the Site Collections which are deleted.

 

 

 

Restore a deleted site collection using Recycle Bin

 

Step 1: Go to the SharePoint Online Administration Center and click Site Collection.

 

 

 

Step 2: On the ribbon, click Recycle Bin.

 

 

 

Step 3: In the Recycle Bin, select the check box next to the site collection that you want to restore.

 

 

 

Step 4: On the ribbon, click Restore Deleted Items.

 

 

 

Step 5: Now click on Restore button to restore the Site Collection.

 

 

 

Step 6: You will be redirected to the Site Collection page from Recycle Bin page and you can see the Site Collection is again restored.

 

 

 

 

 

 

 

Jul 22
Paging using SharePoint 2013 REST API


In this blog, we will have demo of how to implement Paging using SharePoint 2013 Rest API

 

Paging in SharePoint?

Paging allows getting items from a SharePoint list in a chunks instead of getting them all in one shot, this chunk is controlled by two variables:

  • Page size: number of items to be displayed.
  • Page position: current index; in other words; in which page we are right now.

 

When requesting GET call to the List API from JavaScript: "/_api/web/lists/GetByTitle('ListName')/items",  the default results returned are limited to 100 rows.

In this blog, we have given a demo example of Paging using SharePoint 2013 REST API. Lets review all the steps along with example below:

 

Step 1: To create paging using REST API. We first need to create a list in SharePoint. So create list a list name Employee in SharePoint. Add columns like First Name, LastName , Address , Email , ContactNo in It.

 

Step 2: After that create SharePoint Hosted App for Paging. Here Go to Templates -> Visual C# -> Office/SharePoint -> Apps and in that select App for SharePoint and give that a Name and click Ok.

 

 

 

Step 3: Here in What SharePoint site do you want to use for debugging your app? Add the url of your SharePoint online site url. In How do you want to host your app for SharePoint? Select SharePoint-hosted.

 

 

 

 

Step 4: After creating SharePoint hosted app, add Client Web Part (Host Web) page in the project. For that right click the project name and go to Add -> New Item.

 

 

 

Step 5: Here from Visual C# Items -> Office/SharePoint select Client Web Part (Host Web) and click Ok.

 

 

 

Step 6: Now select Create a new app web page for the client web part content and click Finish.

 

 

 

Step 7: The App will look like the below image where there will be Next-Previous buttons and in the property you can set page size as well.

 

 

Step 8: To create custom properties in app, you first need to define that properties in Element.xml file in that Client Web Part you added.

 

<!-- Define properties in the Properties element.
         Remember to put Property Name on the Src attribute of the Content element above. -->
    <Properties>

      <Property
          Name="PageTitle"
          Type="string"
          RequiresDesignerPermission="true"
          DefaultValue="SharePoint Empower News"
          WebCategory="IndexPage Properties"
          WebDisplayName="Page Title"
        WebDescription="Provide the title of page.">
      </Property>

      <Property
          Name="PageLibraryURL"
          Type="string"
          RequiresDesignerPermission="true"
          DefaultValue="https://sharepointonlineempower.sharepoint.com/sites/devsite"
          WebCategory="IndexPage Properties"
          WebDisplayName="Page Library URL"
          WebDescription="Provide the URL to the site that contains the page library with a '/' on the end.">
      </Property>

      <Property
          Name="PageLibraryName"
          Type="string"
          RequiresDesignerPermission="true"
          DefaultValue="News"
          WebCategory="IndexPage Properties"
          WebDisplayName="Page Library Name"
          WebDescription="Provide the name of page library.">
      </Property>

      <Property
          Name="ItemTitleField"
          Type="string"
          RequiresDesignerPermission="true"
          DefaultValue="Title"
          WebCategory="IndexPage Properties"
          WebDisplayName="Item Title Field Name"
          WebDescription="Provide the field name of item title.">
      </Property>

      <Property
          Name="ItemBodyField"
          Type="string"
          RequiresDesignerPermission="true"
          DefaultValue="Body"
          WebCategory="IndexPage Properties"
          WebDisplayName="Item Body Field Name"
          WebDescription="Provide the field name of item body.">
      </Property>

      <Property
         Name="PageSize"
         Type="string"
         RequiresDesignerPermission="true"
         DefaultValue="5"
         WebCategory="IndexPage Properties"
         WebDisplayName="Page Size"
         WebDescription="Provide the page size for number of items per page.">
      </Property>

    </Properties>

  </ClientWebPart>​

 

 

Step 9: Now create a property for SharePoint Hosted app in App.js which we can add once the app will be added to the SharePoint.

function getPageProperties() {

var params = document.URL.split("?")[1].split("&");

var pString;

 

for (var i = 0; i < params.length; i = i + 1) {

var param = params[i].split("=");

 

if (param[0] == "PageTitle") {

pageTitle = decodeURIComponent(param[1]);

$('#index-app-title').text(pageTitle);

}

elseif (param[0] == "PageLibraryURL") {

hostweburl = decodeURIComponent(param[1]);

}

elseif (param[0] == "PageLibraryName") {

pageLibraryName = decodeURIComponent(param[1]);

}

elseif (param[0] == "ItemTitleField") {

itemTitle = decodeURIComponent(param[1]);

}

elseif (param[0] == "ItemBodyField") {

itemBody = decodeURIComponent(param[1]);

}

elseif (param[0] == "PageSize") {

pageSize = parseInt(decodeURIComponent(param[1]));

topVal = pageSize;

lastPage = pageSize;

}

}

 

 

}

It will add Page Title, Page Library Url, Page Library name, Item Body Field and Page Size properties to the app.

 

 

Step 10: Now create a function for Next button in App.js.

 

function onNextPage() {
    $('#index-app-content').empty();
    topVal = topVal + pageSize;
    firstPage = firstPage + pageSize;
    lastPage = lastPage + pageSize;

    //If PageSize will be greater than or equal to TopVal then It will go inside If

    if (topVal >= pageSize) {
        queryUrl = appweburl + "/_api/SP.AppContextSite(@target)/web/lists/getbytitle('" + pageLibraryName + "')/items?@target='" + hostweburl + "'&$select=EncodedAbsUrl,Title,LastName,Address,Email,ContactNo,Id,Modified,EditorId&$orderby=Modified desc&$top=" + parseInt(topVal);
    }

       //If PageSize will be less than TopVal means the data will be less than topval then It will go in else part

    else {
        topVal = pageSize;
        firstPage = 1;
        lastPage = pageSize;
        queryUrl = appweburl + "/_api/SP.AppContextSite(@target)/web/lists/getbytitle('" + pageLibraryName + "')/items?@target='" + hostweburl + "'&$select=EncodedAbsUrl,Title,LastName,Address,Email,ContactNo,Id,Modified,EditorId&$orderby=Modified desc&$top=" + parseInt(topVal);
    }
    execCrossDomainRequest();
}

 

If we click on ">" button; we need to pass parseInt(topVal) this simply tells SharePoint "I need the next X items that come after the item with ID 5".

 

 

Step 11: Now create the function for the Previous Button App.js.

 

function onPreviousPage() {
    $('#index-app-content').empty();
    topVal = topVal - pageSize;
    firstPage = firstPage - pageSize;
    lastPage = lastPage - pageSize;

    //If PageSize will be greater than or equal to TopVal then It will go inside If

    if (topVal >= pageSize)
    {
        queryUrl = appweburl + "/_api/SP.AppContextSite(@target)/web/lists/getbytitle('" + pageLibraryName + "')/items?@target='" + hostweburl + "'&$select=EncodedAbsUrl,Title,LastName,Address,Email,ContactNo,Id,Modified,EditorId&$orderby=Modified desc&$top=" + parseInt(topVal);
    }

        //If PageSize will be less than TopVal means the data will be less than topval then It will go in else part

    else
    {
        topVal = pageSize;
        firstPage = 1;
        lastPage = pageSize;
        queryUrl = appweburl + "/_api/SP.AppContextSite(@target)/web/lists/getbytitle('" + pageLibraryName + "')/items?@target='" + hostweburl + "'&$select=EncodedAbsUrl,Title,LastName,Address,Email,ContactNo,Id,Modified,EditorId&$orderby=Modified desc&$top=" + parseInt(topVal);
        
    }
    execCrossDomainRequest();
   
}

 

If we click on "<" button; we need to pass parseInt(topVal); this simply tells SharePoint "I need the previous X items that precede (come before) the item with ID 4".

 

 

Step 12: Now deploy the project.

 

 

 

Step 13: Now in SharePoint create a page to add your app. For that go to Settings -> Add a Page.

 

 

 

Step 14: Now give name to a page and then click Create.

 

 

 

Step 15: Now in the page go to Page -> Edit to add the app in that page and after that go to Insert -> App.

 

 


Step 16: Now select your app and click ok to add it in the page.

 


 

Step 17: Now after adding the app click on the square at the right of the app and select Edit Web Part.

 

 

 

Step 18: Here you will make all the required changes through Page Properties, in that in Item Body Field Name select Body, Item Title Field Name select Title, List or Library Name select your list Here I have selected Announcement List, List or Library URL select that list url, in Page size select custom page size which will show the data according to that size and give Page Title which will be at the top.

 



Step 19: Here you can see the News App which is created. You can see that there are three news updates coming as we selected Page Size to 3. At the bottom you can see the number of pages is being shown. When you are in the first page only right arrow will be shown as there is nothing before it.

 

 

 

Step 20: Now if you select the right arrow you will go to the other news data in the list. As there are only 4 entries in the list you can see only two entries here and because there are no more data after that the right arrow is disabled and the left arrow is enabled as there are some news before the current news.

 

​ 



You can Download the source code from the below link ->

http://gallery.technet.microsoft.com/sharepoint/Paging-using-SharePoint-c92e718d​


Jul 02
Image Rendition in SharePoint 2013 On Premise

In our previous blog we have seen What is Image Rendition and how we can perform Image Rendition in SharePoint Online The below link is of How we can achieve Image Rendition Online:


Image Rendition in SharePoint 2013 Online


Here are the steps given to perform Image Rendition on SharePoint 2013 On Premise.

 

Step 1: To work with Image Rendition in SharePoint On Premise you need to Enable BlobCache. To Enable BlobCache Open Web.Config file for the web Application. To do that Click Start, point to Administrative Tools, and then click Internet Information Services (IIS) Manager.

 

 

Step 2: In Internet Information Services (IIS) Manager, in the Connections pane, click the plus sign (+) next to the server name that contains the web application, and then click the plus sign next to Sites to view the web application or applications that have been created.

 

 

Step 3: Right-click the name of the web application for which you want to configure the disk-based cache, and then click Explore. Windows Explorer opens, with the directories for the selected web application listed.

 

 

Step 4: Here you can see Web.Config file with other files.Right-click web.config, and then click Open.

 

 

Step 5: Find BlobCache line and set enabled="true". Set folder path to a different folder or keep the default c:\BlobCache\14 folder.

 

 

Step 6: Now open SharePoint Central Administration. From there go to Application Management and then select Manage Site Application.

 

 

Step 7: In Manage Site Application there will be many application. Select one application from there.

 

 

Step 8: Now after doing this go to Settings and from that Site Settings.

 

 

Step 9: Here from Site Collection Administrator go to Site Collection Features.

 

 

Step 10: Now here Activate SharePoint Server Publishing Infrastructure.

 

 

Step 11: Now from Site Settings go to Site Actions -> Manage Site Features.

 

 

Step: 12: Here Activate SharePoint Server Publishing feature.

 

 

Step 13: As you enable BlobCatch in the Web.Config file and activate the above features you will see Image Rendition in Site Setting -> Look and Feel.

 

 

Step 14: Open The Link Image Rendition. Here you can see some in build Image Rendition Templates and you can create your own Image Rendition Templates as well. Here you can do it by clicking on Add New Item.

 

 

Step 15: When you click on Add New Item, you will get the below screen. Here you will need to insert Name, Height and Width and then Save It.

 

 

Step 16: You can Add Image Rendition Templates as per the requirements. Here I have added two of them. Large Desert Template and Small Desert Template.

 

Step 17: Here from Site Settings go to Add a Page.

 

Step 18: Give it a name and click on Create to create a Page.

 

 

Step 19: Now from Pages -> Edit Page and then from Insert -> Picture -> From Computer to add an Image to the page.

 

 

Step 20: Here after adding an image select that image and then from Image on the Ribbon go to Pick Renditions and select your Image Rendition Template.

 

 

 

Step 21: Now After adding one Template the Image will look like this.

 

 

 

Step 22: And when you add another Template to the page, the image will be same but because of the Template will be a different one the width and Height will be changed.

 

 

Step 23: You can crop the chosen image as well, click on the image again and click on Pick Rendition in the Ribbon and choose Edit Renditions.

 

 

 

Step 24: Here below the Image by clicking on Click to Change for cropping the image.

 

 

Step 25: Here you can crop the image and Save it.

 

 

1 - 10Next

 

 ‭(Hidden)‬ Blog Tools