1/25/2019

System.Uri and Site.OpenWeb

Often we're in a situation when we need to get a server relative url from absolute url.
One of the easiest ways to do that in C# is to use System.Uri object like that:
public static string GetRelativeUrl(string absoluteUrl)
{
  return new Uri(absoluteUrl).AbsolutePath;
}
One thing we should remember about this method is: System.Url automatically escapes the url. As a result, as example, https://tenant.sharepoint.com/sites/mysite/Site With Spaces will be replaced with https://tenant.sharepoint.com/sites/mysite/Site%20With%20Spaces, and AbsolutePath will return /sites/mysite/Site%20With%20Spaces.
And that's critical for SharePoint. If you provide escaped server relative url to Site.OpenWeb (or SPSite.OpenWeb for server OM) you'll get File not found exception for CSOM and something like There is no Web named for Server Object Model.
To avoid that and still use System.Uri I would recommend to use Uri.UnescapeDataString static method:
public static string GetRelativeUrl(string absoluteUrl)
{
  return Uri.UnescapeDataString(new Uri(absoluteUrl).AbsolutePath);
}
It will revert back the escaping.
Hope that would help!
That's it for today!
Have fun!

1/20/2019

Add Google Charts into SharePoint Framework Web Part

This post is based on the question in sp-dev-docs repo.
The question is how can we render a Google Charts in SPFx web part.
Actually, it's pretty easy thing to do.

11/08/2018

How to Add Folders and Files into Master Page Gallery on Modern Team Sites

Sometimes, especially when developing custom SharePoint Add-ins, we want to host assets (JavaScript, CSS, etc.) in Master Page Gallery.
This is a pretty standard approach that allows to reference the same resources from sub sites (I know that sub sites are now evil =)) but store everything in one place on root level of the site collection.
Note: it is not necessary to host your assets in Master Page Gallery, it is one of the options. So, take it in mind, that you can use other options as well. But what if we want to use that approach with Modern Team Sites?

10/31/2018

How the versioning works in SharePoint Framework solutions

This post is a sum up of the conversation held in Twitter regarding versioning of your SharePoint Framework solutions.
In package-solution.json file of the SPFx project there is a property version
The description from the currently tells us that:
Optionally, you may also specify a version number in the format "X.X.X.X", which is used to identify various versions of the package when upgrading.

But it doesn't explain what is actually affected by the version update.
So, here is how it actually works:
  • First of all, all the assets (JavaScript files, CSS, images, etc.) are automatically updated as soon as new version has been added to the App Catalog. You don't need to update the app on all of your sites.
  • If you're using Feature Framework and Feature declarations in your solution then these are the resources that need the actual App update.
This situation may lead to confusion but it is what it is.
And actually it makes sense for two reasons:
  1. As an app should be installed to every site (meaning every root site and if needed - every sub site) separately, it's really difficult to go through all the sites and update the app. So, automatic update is a good decision.
  2. Why this "automatic" update isn't applicable to Feature Framework? Because new version of features content (like fields, content types, etc.) could contain breaking changes and it's better to be aware of it. And anyway SharePoint Dev team does not recommend to use Feature Framework in your solutions at all. =)
Here is also a PnP Shorts video that describes how to update the SPFx solution.
Hopefully, this information will be helpful.

Have fun!

9/26/2018

How to: Set List/Document Library View Page as Modern Team Site Welcome Page (Homepage)

When you need to change the Home Page of Modern Team Site in SharePoint Online it's pretty easy to do through UI.
Just go to the Pages library, open context menu for the page you want to make a homepage and select "Make homepage"

But what if the page you want to make a homepage is a Document Library or List View Page that is, obviously, not presented in the Pages library?

9/17/2018

Using Vue.js in SharePoint Framework Applications. Part V: Use React Components inside Vue.js Solution

This is the fifth post about SharePoint Framework and Vue.js. In this post I want to show how to use React components inside Vue.js-based SharePoint Framework solutions.

List of posts:
  1. Whats and Whys
  2. Default SPFx web part using Vue.js
  3. Yeoman generator with Vue support
  4. Web Part Property Pane Control
  5. Use React Components inside Vue.js Solution (this post)
Code: https://github.com/AJIXuMuK/vuejs/tree/master/react-in-vue.

9/06/2018

Using Vue.js in SharePoint Framework Applications. Part IV: Web Part Property Pane Control

This is the fourth post about SharePoint Framework and Vue.js. In this post I want to go through the process of creation custom Property Pane control using Vue.js.

List of posts:
  1. Whats and Whys
  2. Default SPFx web part using Vue.js
  3. Yeoman generator with Vue support
  4. Web Part Property Pane Control (this post)
  5. Use React Components inside Vue.js Solution
Code: https://github.com/AJIXuMuK/vuejs/tree/master/proppane-control.