Showing posts with label Tomasz Szulczewski. Show all posts
Showing posts with label Tomasz Szulczewski. Show all posts

Tuesday, March 15, 2016

Geolocation column in SharePoint

Today I would like to write about something new. I mean that today I am going to write about Geolocation column in SharePoint. This topic is not described to often, which is strange to me as it’s very interesting and also it could be very useful. For my tests and coding I will use SharePoint online. Geolocation column is a new feature, which has been introduced in SharePoint 2013. If you are not familiar with this topic you should read first article at MSDN pages. In general new column give us possibility to keep in SharePoint column (Geolocation column) geographical coordinates, which can be used to build nice looking Bing maps with our custom location. Let’s see how we can do this.

The first step is to get a key for Bing maps which can be generated at this Microsoft portal. For our needs we can use Basic key, which can be obtained for free. But if you plan to build something big probably you will need paid key. If you get your key you can now activate geolocation columns in your site. By default this option in not active. If you run SharePoint on premise you can use PowerShell script.

$EmailAddress = “mojUser”
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($WebUrl)
$Credentials = Get-Credential -UserName $EmailAddress -Message “Podaj hasło do Office 365”
$Context.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($EmailAddress,$Credentials.Password)
$List = $Context.Web.Lists.GetByTitle(“Moja lista“)
$FieldXml = “<Field Type=’Geolocation’ DisplayName=’Location‘/>”
$Option=[Microsoft.SharePoint.Client.AddFieldOptions]::AddFieldToDefaultView
$List.Fields.AddFieldAsXml($fieldxml,$true,$option)
$Context.Load($list)
$Context.ExecuteQuery()
$Context.Dispose()

Some people says that they were able to run this script against SharePointa online, with SharePoint online management shell. Well, I always get in this case errors. I don’t know. Maybe there’s a problem with a files version or something… Microsoft make a lot of changes to Office 365 stack. For my environment I used CSOM, as console application. Works perfect for me.

var webUrl = new Uri("http://ift.tt/251t2Rk");
                using (ClientContext ctx = new ClientContext(webUrl))
                {
                    var login = "user";
                    var password = "password";
                    var secureStrPwd = new SecureString();
                    foreach (char c in password)
                    {
                        secureStrPwd.AppendChar(c);
                    }
 
                    var creds = new SharePointOnlineCredentials(login, secureStrPwd);
                    ctx.Credentials = creds;
 
                    var web = ctx.Web;
                web.AllProperties["BING_MAPS_KEY"] = "Bing key ";
                 web.Update();
 
                ctx.ExecuteQuery();
                 
                List officeLocationList = ctx.Web.Lists.GetByTitle("Moja lista");
                officeLocationList.Fields.AddFieldAsXml("<Field Type='Geolocation' DisplayName='Column name'/>", true,AddFieldOptions.AddToAllContentTypes);
                try
                {
                    officeLocationList.Update();
                    ctx.ExecuteQuery();
                }
                catch (Exception)
                {
 
                    throw;
                }
And that’s all. Please note that our code adds column to existing list! You can’t just activate geolocation column and then add it later to the list with browser. You have to always use code to add such column to the specific list.
Bing MapBing Map

Above you can see a map which displays our location base on the data in SharePoint list. By default you can’t create such view in SharPoint list. But when you activate geolocation column you will get new view template called  “Map View”. There’s one more thing. Geolocation data is difficult to add to the list. In my next post I will show you how to make in easy way.

This post is based on my personal blog.


by Tomasz Szulczewski via Everyone's Blog Posts - SharePoint Community

Thursday, January 28, 2016

Custom SharePoint display template

Custom SharePoint display template you can find interesting when you start playing more with branding. For the last few weeks I was very busy at my new job and during this time I was doing a lot of stuffs related to branding. Of course I am not designer, but still I have learn a lot. Today I would like to write about Custom SharePoint display template. It will be third post related to branding (part 1 and part 2). I guess that many of you saw nice widgets which presents upcoming events. Today I would like to show you how to build something like this as it's not possible to that with default sharepoint configuration. At the begging let me write a few words of some basis.

Display template is responsible for format and style of search related web parts, also it presents managed properties and how it will looks like.

In fact display template has two pieces:
Control Template - it's place holder where result from search engine will be stored. Control template is rendered just one time.
Item Template - it's responsible to single item display, for example descriptions, images, title, etc. Each element is rendered separately. Today I will write about item template.

And just one thing. Content Query Web Part, which is very useful sometime is not search based, which means that you can't make modification to related display template... I lost some time to find out that.

Display template can be a part of branding project, which can be build and stored in Design Package. It's a full branding project, which contains all of customization. Ok, let's come back to our Custom SharePoint display template. In first step we should display design manager for our site collection.

Let me remind you that to do that we need active SharePoint Server Publishing feature in our site collection/site.When we display content of our folder with display templates we will see a lot of files, which are responsible for displaying various data. Describing all those stuffs will take to much time, but in general idea is very similar. And I would like to change how Content Search present single element. Let's search for a file which has a title: "Picture on left, 3 lines on the right". This files is used when Content Search webpart present to us possible options for the Item. You can find more about all those files at Technet. Let's select it and make just simple CTRL-C, CTRL-V with changing file name during copy process. Now it's time for SharePoint designer. We are going to display all files and then we are going to:  /_catalogs/masterpage/Display Templates/Content Web Parts/our_file_name. I would like to mention that when we make a copy of our file SharePoint also created additional file with js extension. We don't touch it, we work with HTML.

First step will be modification of the title tag . Title will be used  in web part configuration page. Now it's time for the file itself, as understanding how it works could be a real challenge:

  • our variables can be accessed with this entry _#=
  • if we want to run JavaScript after our page has been rendered we use code just like below:

<!--#

AddPostRenderCallback(ctx, function() {

//our code

});

_#-->

And following code:

var line1 = $getItemValue(ctx, "Line 1");
var line2 = $getItemValue(ctx, "Line 2");
var line3 = $getItemValue(ctx, "Line 3");

is responsible for values from web part configuration page (managed properties). Now it's time for the code which display day number and first three letters of the month. The code should be at the end of the file:

<!--#_
}
var myDate = null;
myDate = new Date(line3);
var monthNames = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
var myMonth =  monthNames[myDate.getMonth()];
var myDay = myDate.getDate();

AddPostRenderCallback(ctx, function() {             
document.getElementById("monthBox"+line3Id).innerHTML = myMonth
document.getElementById("dayBox"+line3Id).innerHTML = myDay;
            });
_#-->

Let's take a look at the tags where we placed the code. I spent some time to find valid format to make code running. Variable "line3" is third line from configuration page of the web part, and we store there our event date. Then we can use our calculated values in page code:

<div id="CompanyDate" style="float: left; width: 50px; height: 50px; text-align: center; margin: auto;font-weight: bold; font-size:14px">
            <span id="monthBox_#= line3Id =#_"  >month </span>
            <br>
            <span id="dayBox_#= line3Id =#_"  >day </span>
        </div>

This HTML code above has been added to existing one, just before part responsible for image rendering. This ID entry can be strange, but in this way we can create SPAN ID's  in automatic way. Now we need just to publish our file. After that our title should be visible at possible option for the item in the web part Content Search configuration page.  Next time I will show how to configure web part and search service to get the result. And that's all.

This article is based on this post


by Tomasz Szulczewski via Everyone's Blog Posts - SharePoint Community

Thursday, October 1, 2015

Sharepoint branding step by step - part 2

In previous article I wrote about custom master page and how to make SharePoint branding. Also when we work with SharePoint Online (Office365). But there's something more... Microsoft give us more possibilities, which can be used to extend functionality of our page. Let's move to design manager. On "Edit Master Page" page press link „Conversion successful” for our master page. We will be transferred to preview page. We can see there how our main page will be looking when we use our custom master page.

Edit Master Page
Edit Master Page

It's time to the next step. When we press "Snippets" in the upper menu we will open new page where we can make some additional improvements to our master page. From the left we can see:

- Navigation – we can add additional navigation to our page

- Administration – some additional administration features

- Containers – containers for our features

- Web Parts – it's just webparts

- Custom ASP.NET markup – if you need something fancy you can use it to create something non standard

Snippet Gallery
Snippet Gallery

Ok, It's time to show you how can use snippets to build something more than just simple master page. I will show you how we can make conditional display of the interface base on user permissions. From upper menu we select Security Trim -> Show to Authenticated Users.

Security Trim
Security Trim

SharePoint will display detailed options of this feature, and preview window will display us how our snippet works. HTML snippet contains source code which should be used to get expected results. Right now we are interested in Customization - Security Trim. When we change setting of the snippet we can modify his behaviour. We will select from the menu AuthenticationRestrictions  option AuthenticatedUsersOnly. It means that only users who were authenticated will be taken into account. Then from Permissions drop down we should select ApproveItem. This second option allow to see content only by users with Approve Item permissions.

ApproveItems Permissions
ApproveItems Permissions

In additions we can also modify how snippets will be displayed on the screen: border, background colour, etc. When we done our configuration work we press Update button to update code in html snippet windows. Then we can copy our code to clipboard with Copy to Clipboard button.

Security Trim Details
Security Trim Details

It's time to use SharePoint designer. Let's open our master page. Please remember that we still work with html file, not .master. Let's find following code:

<div id="ms-designer-ribbon">
            <!--SID:02 {Ribbon}-->
            <!--PS: Start of READ-ONLY PREVIEW (do not modify) -->
<div class="DefaultContentBlock" style="background:rgb(0, 114, 198); color:white; width:100%; padding:8px; height:64px; overflow:hidden;">

The SharePoint ribbon will be here when your file is either previewed on or applied to your site.

</div>
<!--PE: End of READ-ONLY PREVIEW -->
</div>

This code is responsible for generating upper ribbon on the page.  We are going to paste snippet code above ribbon code, and then we move ribbon code into snippet div's. When we finish our code should looks like this:


<div data-name="SecurityTrimmedAuthenticated">
    <!--CS: Start Security Trim Snippet-->
    <!--SPM:<%@Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"%>-->
    <!--MS:<SharePoint:SPSecurityTrimmedControl runat="server" AuthenticationRestrictions="AuthenticatedUsersOnly" Permissions="ApproveItems">-->
        <!--PS: Start of READ-ONLY PREVIEW (do not modify)--><span><!--PE: End of READ-ONLY PREVIEW-->

<div class="DefaultContentBlock" style="border:medium black solid; background:yellow; color:black; margin:20px; padding:10px;">
       

<div id="ms-designer-ribbon">
            <!--SID:02 {Ribbon}-->
            <!--PS: Start of READ-ONLY PREVIEW (do not modify) -->
<div class="DefaultContentBlock" style="background:rgb(0, 114, 198); color:white; width:100%; padding:8px; height:64px; overflow:hidden;">The SharePoint ribbon will be here when your file is either previewed on or applied to your site.</div>
<!--PE: End of READ-ONLY PREVIEW -->
        </div>
        </div>

<!--PS: Start of READ-ONLY PREVIEW (do not modify)--></span><!--PE: End of READ-ONLY PREVIEW-->
<!--ME:</SharePoint:SPSecurityTrimmedControl>-->
<!--CE: End Security Trim Snippet-->
</div>

It's time to save our work. And that's all. Now when user will display page he will be able to see ribbon only if he has valid permissions. It's only simple example how snippets works, but the idea how to use other is very similar. There's much more than this - you should make your own tests.

This article was originally posted at my personal blog.


by Tomasz Szulczewski via Everyone's Blog Posts - SharePoint Community

Wednesday, August 26, 2015

How to make SharePoint online branding

Today I would like to write a few words about branding. I have to make branding for my company internal site and I would like to say that it was something new to me. I was working with SharePoint online and current post is based on this environment. Let me point one thing at the begging. Microsoft in general is against branding, especially if you want make some deep changes. I understand that, as I had cases that after some modification in SharePoint itself branding was destroyed. It's very important in case of Office 365 where some changes can be done by Microsoft without prior information. But in some cases site should look nice to the users, for example if it's central site of the company, with marketing or business information. It should be good looking. I will present my approach from my point of view as the guy who's not graphic skills. 

At the begging we need design for our site. We have to remember that we should avoid some features like flash or silverlight.  On other hand we can get really amazing results with HTML 5, javascript, Bootstrap, etc. You can find a lot of free designs on the Internet. For example you check this site. Let's download our template and then open it in Visual Studio or other editor. At the begging we should remove everything which will not be used in our project, like scripts, images, pages, etc. Usually we will stay with single page, scripts and css's. Also we should check if our project is not calling to external sites. It's not big deal but we should remove everything with external http links. In this case user will get warring about non secure content in every page refresh - it will very annoying to him. One more thing - images. Our master page can use for example slider or other solution with images. But it's important to put images in Master Page Gallery! Of course we can use image library and put the link in html code. Unfortunately in this case we will see delay during image loading, which make this approach not useful to us. The last project, which you can see below was 1.8 Mb. And the images were half of this size. Also big size has Font Awesome.

Master Page
Master Page

Ok, let's move to the SharePoint. To make our branding possible we have to activate for our site collection publish feature (Publishing Infrastructure): Site settings - > Site Collection Administration - > Site collection features and here we turn on SharePoint Server Publishing Infrastructure. It will take a while… Then we are going to Site Settings -> Site Features and turn on SharePoint Server Publishing. We can check that everything is in place if we can see Design Manager option in the menu.

Design Manager
Design Manager

And the design manager is new option in this version of SharePoint. More information you can find at the MSDN site. This amazing tool provide to us possibility to convert html project into master page. Let's move to Design Manager page. We will see there menu as below:

Design Manager Menu
Design Manager Menu

There are following options there:

2. Manage Device Channels – here we can configure display options base on device

3. Upload Design Files –  files loading to the server

4. Edit Master Pages – we can convert our project into master page here, and also we can create some SharePoint snippets

5. Edit Display Templates – we are checking display templates there

6. Edit Page Layouts – we create here new  page layouts

7. Publish and Apply Design – and here we can publish our master page

8. Create Design Package – Finally we can create package which can be reused in other projects.

It's time to move forward. Let's send our data to the Office 365 server. From design manager menu we select option Upload Design Files. We will see link to the  Master Page Gallery. We can click it and the library should be mapped as local network disk. And there we should load our data. One thing. This option works well with internet explorer, even Windows 10 Edge doesn't work correctly with this feature. If the previous operation wasn't successful you can copy the link, open new card in IE and after displaying content of the  master page gallery we can press option: Open with Explorer.

Master Page Gallery
Master Page Gallery

After some time content of the master page folder should be mapped as network drive. If it's still doesn't work you can check this link to try solve the problem. Create folder for our master page and load content of our project - do not load single files into the root, as we get a mess there. Next step is publishing of all items which were sent to the server. To avoid clicking item be item we can use option: Site Content and Structure, where we can publish multiple items wing one click.

Site Content And Structure
Site Content And Structure

After publishing all files it's time to the final move. Go to the design manager and select option: Edit master pages, and then: Convert an HTML file to a SharePoint master page. We select our html page, which should become a master page. After some time our brand new master page should become visible. It's important that the status should be Conversion successful.

Convert to master page
Convert to master page

If we get some errors we should remove code which is the source of the problem. Ok, it's time to publish our master page. Again move to master page gallery and again select our html  file and press publish. We do not click on the master page, which exits now there!

Small remark here. We always work with HTML file, not master page itself. It's the SharePoint task to synchronize all changes which we make to the page.

This article was originally posted at my personal blog.


by Tomasz Szulczewski via Everyone's Blog Posts - SharePoint Community

Thursday, May 28, 2015

Power of the content type

In general most of us working with SharePoint know what the content type is. A SharePoint content merge together an item and information about the item.We can use different kinds of items: a document, an excel workbook, a KPI's, etc. With this approach we get metadata which can be used in many ways. All those information are obvious for most of us and it's basic knowledge for all SharePoint people. So why I am writing about it again? Because again I get the project which was previously developed by some super SharePoint heroes. And there are many libraries, lists without any single site collection column or content type! Isn't it amazing??? And now If I want to make any modification I have go through all libraries/ lists and check one by one. Just wonderful! So I would like to remind to everyone who are new to SharePoint or maybe they forgot what does it mean power of the content type.

1. How to add column in lists/ libraries. It's really simple. We just press the button "Create column", enter column name and that's it. Here is the column.

New Column
New Column

This approach is very simple and it not require any magic knowledge, any user with proper permission can do this. Well and that's all good news. What about case when we have more libraries or list where we want to store the same kind of information and then we want to change something? In such case we have go through them, one by one... It's the best way to create a chaos across the farm.

2. Much better solution is to use site column. It's very simple. You just need to enter "Site settings" and create column at this level. It looks like very small difference, in both cases we just created column, but the this small difference make a huge impact. First of all this columns flows down. I mean that it's available in all subsites. And in this case if we make modification it will be visible in lists/ libraries across the site collection! Also if we set our column as "Lookup Site Column" our "lookup" also works in other sites! It could be very useful if we run free sharepoint version and we can't user Content Query Web Part...

 

Site Column
Site Column

 

3. Now it's time to add knowledge from previous point add create our own content type. It's not a rocket science. We just have to go to site settings, then we go to site content types, and then we just create our own content type. Please remember that we should rather put it into our own group. It will make easier administration. Also we should highlight that it's also is available across the site collection, which means that our changes are made in single place and then SharePoint will replicate it.

Content Type
Content Type
New Content Type
New Content Type

 

As you can see it's not a big deal, but this approach allow us to use useful futures of SharePoint - Power of the content type. This power is related to centralized management. When we use columns and content types at site collection level we can keep our farm clean, without a mess. And sometime when we someone has to make our work it will be much faster and easier to find out how everything works.

This post was originally posted on my blog


by Tomasz Szulczewski via Everyone's Blog Posts - SharePoint Community