Some thoughts on programming stuff

Category: Coding (Page 2 of 2)

Restart Timer and Admin in SharePoint

SharePoint relies on Timer Service and Admin Service to run and manage its tasks. As any Windows Service, sometimes we need to stop and start them. That’s why I wrote this post to share a script on how to restart Timer and Admin in SharePoint.

These services are present in a SharePoint Server, inside the Windows Services list. There you can see both SharePoint Administration and SharePoint Timer Service:

  • The Admin Service performs administrative tasks for Windows Services under the Local Admin Network rights;
  • The Timer Service sends notifications and performs scheduled tasks for SharePoint services. It must run with an Account with Admin rights to server.
Timer and Admin Services - Restart Timer and Admin in SharePoint
Timer and Admin Services

Script to restart the timer and admin services

The script will load the SharePoint PowerShell dependencies and start by restarting the services in each machine present in the farm. This can throw an error if the Windows Servers are not properly configured to allow remote changes to their services.

Finally, in the end we use some objects provided by the SharePoint DLL to ensure that every Timer service is online and available.

There are other services required to run SharePoint, but it depends on how you are exploring its features. Here is the list of possible mandatory services that you may face and even restart if you want (haha):

  • SharePoint Tracing;
  • SharePoint User Code Host;
  • SharePoint VSS Writer;
  • World Wide Web Publishing Service;
  • SharePoint Server Search.

That’s it! I hope this post can be helpful when you want to restart Timer and Admin in SharePoint. Also you may find useful other posts related to PowerShell in the blog posts available.

References:
StackOverflow

Export user permissions in SharePoint

This post will present a Powershell script that will let you Export user permissions in SharePoint from all Web Applications and their Site Collections.

The script creates a CSV file and fills the data in the columns like below:

  • Site Name;
  • Site Url;
  • Name of the Group;
  • Login of the Group Owner;
  • Display name of the Group Owner;
  • User Login (who has the permission);
  • User Display Name (who has the permission);
  • The role or permission the user has.
Report after being exported (in Brazilian Portuguese) - Export user permissions in SharePoint
Report after being exported (in Brazilian Portuguese)
Continue reading

Get thumbnail URL programmatically in SharePoint

SharePoint Picture Libraries offer an out-of-box feature for image compression and optimization, specially when working with thumbnails. After uploading an image to a Picture Library, you will be able to get an optimized version and thumb version just calling the same image using an specific URL pattern. In this blog post we cover a simple JavaScript function that lets you get picture thumbnail URL programmatically in SharePoint.

First, it’s important to say what is a thumbnail! According to Wikipedia, “Thumbnails are reduced-size versions of pictures or videos, used to help in recognizing and organizing them, serving the same role for images as a normal text index does for words”.

It’s extremely useful when you need to develop a custom web part to present an image inside a Library and you want to save bandwidth for your users at the same time that your site has better performance too. Working with the thumbnail version of your images will let SharePoint handle cache and performance in a more efficient way, making your system more reliable and faster.

Image result for thumbnail image example
Example of thumbnail usage (Open Berkeley)

So how to get the picture thumbnail URL programmatically in SharePoint?

Generating the thumbnail URL

Explanation of thumbnail URL feature in SharePoint

Basically it works transforming a given string in another one that respects the pattern required to generate the URL. You just need to pass an image URL that is stored inside a Picture Library. It will transform an URL like the example below and you can get thumbnail URL programmatically in SharePoint:

In addition to that, if you are working with images you may end up facing some problems with Image Renditions. Maybe this post is for you!

References:
StackOverflow

Export Workflow History to CSV in SharePoint

Sometimes you may need to export Workflow History to CSV in SharePoint, just because most of the history data is not available anymore in the Workflow History page of a document or item, thanks to the SharePoint Workflow Auto Cleanup that purges the data for performance purposes.

But what happens if someone is trying to make an audit review and cannot find the history for a specific document? Well… you can use this script!

Export Workflow History to CSV in SharePoint - Audit and reporting of document history
Audit and reporting of document history
Pxhere
Continue reading

Get current page layout with JavaScript in SharePoint

Today I’m bringing an useful code snippet to get current page layout with JavaScript in SharePoint. It helped me on finding out which Page Layout I was running my JavaScript code. Here you can find a pure vanilla JavaScript example that builds the URL for the SharePoint REST API. First it requests only the PublishingPageLayout field of the current page. Then it logs the information in the console, but I suggest you to just do that for testing purposes.

Page layouts are used in SharePoint to customize and define where the content will be displayed in your Web Page. Essentially, it’s a template for your Web Page that helps you on building a better experience. It benefits those who access your content and to help the content creators when they need to create a new page for you Site or Intranet.

Page layouts must be attached to a Content Type, so you can reference site columns and fields inside the template to let SharePoint save and present the data in the page library just like any document library you had been working with. Also it let’s you define different ways to present the fields, for example the Title or the Page Content, when in the Display Mode and Edit Mode.

This script can be particularly useful when you need to accomplish some specific business logic that requires to run a JavaScript function in an specific layout and you can’t or don’t want to make changes to the page layouts directly. I say that because, due the fact that Page Layouts are just like templates, you can add Script tags directly to the Page Layouts and call only the JavaScript files you /want when a user selects that Page Layout during the content creation process.

Image result for sharepoint page layout
A bunch of Page Layouts – dotnetcurry
Continue reading

Access ADFS-secured Web API via Angular SPA

This blog post you cover the important steps for implementing a project that allows you to to access ADFS-secured Web API via Angular SPA. It’s important to have the ADFS Application Group configured properly.

If you haven’t setup the Application Group yet, just check the post to learn how to create and configure it.

We will be using JWT to make the authentication because JSON Web Tokens are an open, industry standard RFC 7519 method for representing claims securely between two parties.

The objective

Our main objective is getting to the login screen in our Angular application and receive a JWT on our callback page, which will be also our index page. So this App will get some data from the Server, another application built as a Web API in .NET.

The project source code is stored in GitHub:
https://github.com/wiliammbr/adfs-angular-webapi

AD FS Sign in Page
Continue reading

File Constructor support in Internet Explorer

As you may know, the File constructor support in Internet Explorer doesn’t exist. For security reasons, you may not be able to abstract the File object as you would like to do normally. It doesn’t if other Libraries that use the File API to upload files like the ng2-file-upload require it, it won’t work.

According to MDN Docs, the File interface provides information about files and allows JavaScript in a web page to access their content. A File object is a specific kind of a Blob, and can be used in any context that a Blob can. In particular, FileReaderURL.createObjectURL()createImageBitmap(), and XMLHttpRequest.send() accept both Blobs and Files.

Since we needed to create Text Files from a TextArea input in a browser and IE didn’t allowed me to do that, after finding the solution for that I’ve decided to share with you what I’ve done to solve the problem in our project while using vanilla JavaScript.

Image result for file
A bunch of files (Findel International)
Continue reading
Newer posts »

© 2024 wiliammbr's blog

Theme by Anders NorenUp ↑