Wednesday, 31 January 2018

SharePoint Framework Property Controls

Developers have started use of SharePoint framework for developing the client side web parts in SharePoint online(Office 365). Some of the code block is getting repeated across multiple client side web parts like selecting the list, date time selection, color picker, term set picker. Developers have noticed this to the PNP community. Hence Microsoft came up with reusable controls which are similar to our ASP.net concept of user controls. This controls can be added to the web part easily and can be used as custom property in property pane. I didn't find all steps in single blog so decided to summaries here starting from creating the client side web parts.



Step 3 : Install the following dependency to your project

Make sure that node.js command prompt is running and it is referring to your project. Execute the below command.
npm install @pnp/spfx-property-controls --save --save-exact
 Step 4 : Update the configuration file of your project

Go to Config folder, under that open config.json file and add the following line to the localizedresource property.
"PropertyControlStrings": "./node_modules/@pnp/spfx-property-controls/lib/loc/{locale}.js"
"localizedResources": {
    "CustomucwebpartWebPartStrings""lib/webparts/customucwebpart/loc/{locale}.js",
    "PropertyControlStrings""./node_modules/@pnp/spfx-property-controls/lib/loc/{locale}.js"
  }
Step 5 : Adding control to your web part

There are around 6 controls currently available.


  1. PropertyFieldColorPicker
  2. PropertyFieldDateTimePicker
  3. PropertyFieldListPicker
  4. PropertyFieldPeoplePicker
  5. PropertyFieldSpinButton
  6. PropertyFieldTermPicker
we will use PropertyFieldColorPicker control. Import the following module to your web part file.

import { 
  PropertyFieldColorPicker
  PropertyFieldColorPickerStyle 
from '@pnp/spfx-property-controls/lib/PropertyFieldColorPicker';

Add the new property in web part name it color of type string
export interface ICustomucwebpartWebPartProps {
  descriptionstring;
  colorstring
}

Add the custom property control to the group fields of the web part property configuration.
 PropertyFieldColorPicker('color', {
                  label: 'Color',
                  selectedColor: this.properties.color,
                  onPropertyChange: this.onPropertyPaneFieldChanged,
                  properties: this.properties,
                  disabled: false,
                  alphaSliderHidden: false,
                  style: PropertyFieldColorPickerStyle.Full,
                  iconName: 'Precipitation',
                  key: 'colorFieldId'
                })   
To test the web part, display the property value in Render method.
 <p class="${ styles.description }">${escape(this.properties.color)}</p>      
Now run the gulp serve to test property locally.

Add the web part on workbench page then click on edit and in property pane you will see the color property with color picker option available. You can select the color and same value will be displayed in the web part body.






Enjoy coding !!!
Reference:
  1. SharePoint framework property control

Thursday, 4 January 2018

PowerShell Start SharePoint incremental crawl

Many times we have scenario where we want to start the incremental crawl after updating some data in SharePoint using power shell, here we can use the below script.


Get-SPEnterpriseSearchCrawlContentSource -SearchApplication "Search Service Application" | where-object { ($_.CrawlStatus -eq "idle") } | foreach { $_.StartIncrementalCrawl() }

Enjoy coding !!!

Read file from FTP location using Powershell


To read the file from the FTP, we can use below script:

$webclient = New-Object System.Net.WebClient
$webclient.Credentials = New-Object System.Net.NetworkCredential('ftp username','ftp password')

$uri = New-Object System.Uri('ftp path')

$webClient.DownloadFile($uri, 'local path') 

Migration issues for SAP.Connector.dll from Win 2003 to Win 2019 server

Recently I got task of migration of asmx web services from windows 2003 to windows 2019 server. These web services fetch data from SAP us...