Thursday, May 4, 2017

Get List Items using SPFx

As we already see about SharePoint client side webpart creation. Now will have a look about getting list items using this. Create the client side webpart first. Click here for the steps.

Open the client side webpart in Visual Studio Code. We can able to see all the needed folder over there.
src section is having all files about the webpart. We need to write the logic in tsx file which is under component folder.
We have a render method in that file which is used to display the content. SPFx will give the default content with welcome message. We can remove this and add our content.

Getting List Items

We may use REST API to get content from list. Will see about the steps for SPFx. Create a componentDidMount() method. We have to place our code in this method only. Before that create constructor for initializing the state. 
Now create componentDidMount() method. We may use axios to call REST API. We have to install this using npm. npm command is:

npm install axios --save

import this in header of the tsx file. 
import axios from 'axios';

Place the below code in the method:

 var items = [];
    var apiPath = "/_api/web/lists/getByTitle('listName')/items";
    axios.get(apiPath).then(result => {
      for (var i = 0; i < result.data.value.length; i++) {
        items.push({
          title: String(result.data.value[i]["Title"]),
          desc: result.data.value[i]["Description"] != null ? String(result.data.value[i]["Description"]) : ""
        });
      }
      this.setState({ listItems: items });
    }
The value has been assigned to listItems state. Next we have to render this. Place the below code in render section.

  return (
       <div>
          {
            this.state.listItems.map((lItems, index) => {
              return (
                <div className="divVehicleContent">
                  <h1>{lItems.title}</h1>
                  <div dangerouslySetInnerHTML={{__html: lItems.desc}}></div>
                </div>
              );
            })
          }
        </div>
    );
That's all compile this using gulp command. Run this code in SharePoint site workbench.

Creating SharePoint Client Webpart (SPFx)

Introduction

As all we know SharePoint has introduced Client Side Webpart using SharePoint Framework. Let we see How to create SPX Client Webpart.

SPX Client Webpart

First install yoeman command in your machine globally. Command to install this,

npm i --global yo

Choose your directory and create a webpart using below command.

yo @microsoft/sharepoint

It will ask some parameters to create a webpart.


I chose React JS for client side script. SharePoint gives an option to create in Knockout JS also. Press Enter after giving webpart name and description. It will some time to complete the create process.We will get a success message once webpart has been created.
Go into the path of solution in command prompt itself and give gulp serve command to run the solution. Gulp serve helps to compile and run the webpart using virtual server.
We will get the localhost workbench once webpart has been compiled properly. We have to add our webpart in workbench.
We will get Welcome screen from client webpart once added.
This is the way to add simple client side webpart using SPX. We will see about getting data from sharepoint using this webpart and hosting in next article....

Monday, January 23, 2017

Export and Import SitePages Library in SharePoint

As all we know about SitePages Library in SharePoint. This Library contains both wiki and webpart pages. We can able to export and import this library using powershell script. Here is the powershell script to export library

Export-SPWeb -Identity "http://yoursiteurl" -ItemUrl "/LibraryName" -Path "c:\temp"

Import-SPWeb  -Identity "http://yoursiteUrl" -Path "C:\temp\filename.cmp"

Thursday, September 22, 2016

Queue Job Status shows "Waiting to be processed" and then never completes

We may get this issue while checkin the project. We can't do anything when we got this message. Project sever will allow you to edit the task once the project checked in. 

Solution for this issue:

  • Goto Services
  • Restart Microsoft Project Server Queue Service 2013 
Check in process will work once you refresh it.

Tuesday, July 19, 2016

Create Custom Page Layout in SharePoint 2013

Introduction

As well know about page layout in SharePoint. Now i am going to give steps to create custom page layout.

Design Manager

We will use design manager to create page layout.  Here is the steps
  • Site Settings -> Design Manager
  • Click Edit Page Layouts
  • Click Create a page Layout
  • Give name for page layout ,masterpage to inherit and content type of page
  • Click Ok
  • New page layout will be displayed in Master Page Gallery and Edit Page Layout page

The page layout is in draft state by default. It will not display in page layout dropdown if it is in draft mode. We have to change this as publish version. Then only page will be displayed.

For making changes to page, we have to change the .html file. Download the .html file and make the changes. upload again in master gallery.

Then, Go to Pages Library. Click Pages in New Document Menu

We can find our custom page in page layout section.

Monday, July 18, 2016

Cannot rename old site on restore


Some of us may face this "Cannot rename old site on restore" error while restoring Site in SharePoint. There may several reason to get this type of error. I am going to say about one of the reason to get this error. 

That's Long URL problem with Libraries and List attachments. Some of the URL can't be restored due to long URL. Here is the steps to find those long URL items.

  • Open the Content Database in SQL
  • Right click the DB and select New Query
  • Paste the below query
    SELECT
   CONCAT([DirName], N'/', [LeafName]) AS [FullRelativePath],
   LEN(CONCAT([DirName], N'/', [LeafName])) AS [Length]
    FROM
   [dbo].[AllDocs]
    ORDER BY
    [Length] DESC

  • We will get the Long URL Libraries and List items
  • Then go to that library / list
  • Delete the Library / List from site. It will be in Recycle bin. No need to worry about that
  • Then take new backup of your site and try to restore it
  • Restore the deleted library / list from recycle bin once site has been restored successfully

Thursday, June 23, 2016

To avoid Threshold for list in SharePoint 2013

Introduction

As all we know about Threshold in SharePoint. It is setting limit to view the list items. Threshold for normal user 5000 and 20000 for admins. If particular list exceeds this limit, then items will not be displayed in listview. We have 2 alternate options to resolve this. Let see one after one.

SPList.EnableThrottling

This option normally in true state for every list. If we disable this, List doesn't consider about threshold value. So List view will display items when list items exceeds threshold limit. Execute the below powershell script to disable this option. (But we have to consider about performace while running with huge amount data in list)

$web = Read-Host "Enter site URL : "
$spweb= Get-SPWeb $web
$listname = Read-Host "Enter List Name:"
$list = $spweb.Lists[$listname]
$list.EnableThrottling = $false
$list.update()
Write-Host "Throttling has been disabled..." -ForegroundColor Green

Daily time window for large queries

We are having this option in Request Trotting. We have a timer option in it. We have to set the time when and how long it will be visible. But we have to consider about performance, when we give long duration.