Showing posts with label pnp. Show all posts
Showing posts with label pnp. Show all posts

Friday, June 7, 2019

PnP Modern Search Web Parts June 2019 release is out

Get it at https://github.com/SharePoint/sp-dev-solutions/releases/latest

Modern Search Web Parts v3.4.0.0

pnp-react-search-refiners.sppkg
Changes
  • Updated to SPFx v1.8.2
  • Added query language setting
Fixes
  • Translations
  • Improved loading placeholders
  • Improved hash paramater change handling

Modern Search Custom Renderer v1.0.1.0

react-search-refiners-renderer.sppkg
  • First binary release
  • Includes example custom code renderer when Handlebars is not enough



Monday, May 28, 2018

How to reset a modern home page using PnP PowerShell


Photo by Nikita Kostrykin at Unsplash

Here’s a short snippet which will reset any modifications done to a modern home page back to the default layout.

Basically you clear out the CanvasContent1 field which stores the page layout and contents.

Connect-PnPOnline https://<tenant>.sharepoint.com/sites/mysite
# Get welcome page url
$web = Get-PnPWeb -Includes WelcomePage
# Load the page
$file = Get-PnPFile -Url $web.WelcomePage
# Get the page's item
$item = $file.ListItemAllFields
# Load the item id
Get-PnPProperty -ClientObject $item -Property Id
# Clear the content to reset
Set-PnPListItem -List SitePages -Identity $item.Id -Values @{"CanvasContent1"=$null} -SystemUpdate

Tuesday, May 8, 2018

How to get the list item from a file URL using PnP PowerShell

image
Photo by Karly Santiago at Unsplash

This is one of the snippets I always forget, but which is very handy in cases where you have the absolute URL to an item in SharePoint. The magic is really line 6 which uses the static method WebUrlFromFolderUrlDirect to get the web URL of the file, so that you can connect properly.

[Updated 2021-01-19 to support "People with existing access" sharing URL's]

$uri = [Uri]'https://contoso.sharepoint.com/sites/foo/bar/Shared%20Documents/mikael-is-cool.docx'.replace(":w:/r/","")
$uri = [Uri]$uri.OriginalString.Replace($uri.Query,"")
# Connect to the root site, or any other site
Connect-PnPOnline -Url ($uri.Scheme+'://'+$uri.Host)
$ctx = Get-PnPContext
# Get the web url for the file
$webUrl = [Microsoft.SharePoint.Client.Web]::WebUrlFromFolderUrlDirect($ctx, $uri)
Connect-PnPOnline -Url $webUrl
$fileItem =  Get-PnPFile -Url ([System.Web.HttpUtility]::UrlDecode($uri.AbsolutePath)) -AsListItem

Sunday, May 6, 2018

Locating where a term set is used in SharePoint using search

Joanne Klein asked on Twitter if there is a way to get all places where a specific term set is used in SharePoint.

image

One way would be to iterate all site collections and check if the term set was present in the Hidden Taxonomy List, which stores all used terms on a site collection (and if you have no idea what that is, that’s ok as well).

image
Hidden Taxonomy List at /Lists/TaxonomyHiddenList/AllItems.aspx

Another option which is the solution I proposed, is to use search. Of course you need to have read access to the items where the term set is used for it to be 100% accurate as well items using terms from a term set has to be present in the search index.

Friday, September 22, 2017

Resolving assemblies when using PnP Core and ADAL / Graph

This is a super technical post and it goes like this:

image

If you use NuGet and reference PnP as well as ADAL and Graph clients as I have above, and you write code to apply a pnp template you might run into DLL hell and get the following exception:

"Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information."

The reason is that PnP take a dependency on both of these libraries, but on older versions. Deep in the code PnP uses reflection to find all serializer types, and it will throw up an assembly loader exception due to you having newer versions of these DLL’s in your project.

You can either align your dependency with what PnP uses, or you add an assembly redirect from the older to newer versions. Below is code which will dynamically resolve to the newest version for these issues.

Note: This assumes your version is newer than whatever PnP takes a dependency on

Add the code in a static constructor, or somewhere else which ensures it runs once for your application.

public static void RedirectAssembly()
{
    var list = AppDomain.CurrentDomain.GetAssemblies().OrderByDescending(a => a.FullName).Select(a => a.FullName).ToList();
    AppDomain.CurrentDomain.AssemblyResolve += (sender, args) =>
    {
        var requestedAssembly = new AssemblyName(args.Name);
        foreach (string asmName in list)
        {
            if (asmName.StartsWith(requestedAssembly.Name + ","))
            {
                return Assembly.Load(asmName);
            }
        }
        return null;
    };
}

Funny part is that it now works fine for me without this code – but, just in case :)

Friday, April 21, 2017

Creating a .pnp provisioning template file

SharePoint Patterns and Practices

After my demo on the PnP screen cast where I showed a provisioning solution based on PowerShell and Azure web jobs, I’ve had some questions about how you go about creating the .pnp files we use for provisioning templates.

There are basically two options, and it’s quite easy. For full samples run Get-Help <command> –Examples on the command lets. If you want to use code instead of PowerShell, look at the PowerShell code in github and see how it’s all implemented.

Generate .pnp file from a site

Connect to the site, and then run:

PS:> Get-PnPProvisioningTemplate -Out template.pnp

By naming the output .pnp, you get a .pnp file instead of and .xml file.

Generate .pnp file from a template xml file

This works for both a single .xml file, or one referencing artifacts.

Make sure the .xml file and all artifacts are stored in a folder. Then run:

PS:> Convert-PnPFolderToProvisioningTemplate -Out template.pnp -Folder c:\temp

It’s important that the .pnp file has the same name as the .xml file inside the folder, due to convention when applying the template, as you can have multiple .xml files in a complete template referenced with <xi:include> statements.

Saturday, January 21, 2017

How to rename the Title field in a list/library using PnP templates

Took me some testing to get this right, but turned out not that hard. You add a reference to the Title field with the out-of-box id fa564e0f-0c70-4ab9-b863-0177e6ddd247, and then change the display name. In the sample below I’m also using a reference to a language resource as I need support for four languages.

<pnp:ListInstance Title="My List" TemplateType="100" Url="Lists/MyList">
    <pnp:Fields>
        <Field ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" Type="Text" Name="Title" StaticName="Title" DisplayName="{resource:MyList_MyTitle}" />
    </pnp:Fields>
</pnp:ListInstance>