PowerShell Error When Restoring Site Collection

SharePoint doesn’t allow the backup of a site collection and restore it in the same content database. If you backup a site collection and restore it, it will give you the following error.

So you need to make a new content database in the web application (in case the replication of the site collection at the same content database) so that the backed up site collection and the restored one are in different content database, but be careful to put the first database offline before you restore the new site collection.

 

HTML6 .. Already?

There have been a lot of buzz on the internet about the release of HTML6,  and seems like it’s going to replace a lot of stuff we used to do with JavaScript (if it’s approved) .. more than HTML5 could do.

The idea is to have <FIXTURES> tag in the Head tag of the HTML page, this Fixtures tag is a repository of code, each code block is called a model, and this model can either be static or it can be retrieved dynamically from SQL. These fixtures are then referenced in the body tag. So in the body tag of your HTML page you can reference chunks of HTML content that was declared previously in the Head tag, which can be static or dynamic, without needing JavaScript. This seems to be the replacement of the Single Page Application model (SPA) that’s currently implemented using some JavaScript frameworks such as Angular. So each part that will be changed will be inside a model in the Fixtures tag.

To read the proposal for the HTML6, have a look here:  https://lists.w3.org/Archives/Public/public-whatwg-archive/2015Mar/0071.html

Client Side Rendering in Forms In Depth

 

SharePoint gives new capabilities that developers can use to do same tasks required in previous versions of SharePoint using client side technologies. The main capability introduced in SharePoint 2013 is CSR (Client Side Rendering). The most common used method for CSR way is to manipulate users data for fields or list views.. But what about forms?

Someone is going to say: “Yes, SharePoint provides JS Link property for list forms as well, so what’s new with it?” Well, there’s more into it. Let’s see what can be done in list forms and to what extent we have the flexibility to do the forms we want.

Here we have a list called Customers, with a new form that looks like this:

 

csr1

Now, we want to make this look different, so we’ll be using JS Link for that. If you edit the newform page, and edit the web part:

csr2

Then go to Miscellaneous, you will find three important properties there:

  1. Form Template Name
  2. JS Link
  3. CSR Render Mode

 

csr3

 

We know that with JS Link we will be able to add a JS file and manipulate our form’s design. We also know that CSR Render Mode being set to standard it tells SharePoint to renders the form using CSR, and setting it to Server Render will make it depend on XSLT for that. But what about Form Template Name and its ListForm value?

If you had experience with SharePoint customization from previous versions specially for forms, you know that SharePoint uses technique called: Rendering Templates. Which is a group of predefined templates SharePoint has and uses them to render its pages and forms. If you have an on premises environment, you can go to this path: SharePoint Hive\TEMPLATE\CONTROLTEMPLATES, you will find a file called: DefaultTemplates.ascx:

csr4

 

If you open that file, you will find many controls with the tag: <SharePoint:RenderingTemplate.. . If you search for ListForm, you will find that it’s actually a rendering template that SharePoint uses to render its forms. But the good thing to know is, you can use another value which is CSRListForm. But what’s the difference?

The difference is that ListForm renders everything for you from SharePoint, like the layout for the form, the label names and so on, so if you need to use JS Link to style your list forms while you are using ListForm rendering template, you would need to use jQuery to restructure your HTML. So what if we use CSRListForm instead? Your list form would look like the following:

csr5

It will only render the fields for you, no labels, no buttons, no spaces between fields, nothing.. just fields. So you will have a clean output that you can play with in JS Link as much as you like! That’s neat!

Now let’s add a JS Link property to a .js file and try to style our form, there’s a file that my friend Muawiyah Shannak created and posted on MSDN, you can download the JS Link file here: https://code.msdn.microsoft.com/office/CSR-code-samples-11-Fully-54ebcaa6

Here we are declaring the objects necessary to form our view:

 

Inside the viewTemplate function we have the following code:

 

As can be seen, we’re constructing the HTML for our form, for this article and on MSDN, we made it static just for learning and explanation purpose. You can do whatever technique you prefer to form the HTML.

Three things to note about this code:

  1. Note how we have {{placeholders}} for each field we want to add in our HTML.
  2. Note also the getSPFieldRender function, I’ll explain that later on.
  3. The input button has an onclick function = SPClientForms.ClientFormManager.SubmitClientForm(‘{{FormId}}’) . This will allow us to use the out of the box capabilities to leverage the submit action and handling validations in the form.

Back to getSPFieldRender, this will go look into the form for each field by its internal name, and will get this field’s HTML, which will be replaced instead of the place holders such as {{TitleCtrl}}. This happens by using the CurrentFieldSchema and drilling down to the Field’s HTML from the ctx.Templates.Fields, As shown below:

 

Now, when apply this JS Link to our list form, SharePoint will render the fields, and place them instead of our placeholders, it would look like below:

csr6

Without using any jQuery hacks, you can now apply your designs to your list forms with the use of CSRListForms.

Hope that gave more understanding to List Forms and CSR.

Focused Inbox and Office 365 Emails

Microsoft introduced a feature called Clutter, that will route emails that don't seem important to the user to another folder called Other. This was a good approach to help users focus on emails that would be important to them, and they can check the Other folder later on, however, users needed to visit another folder in order to see emails. That's why Microsoft introduced Focused/Other filters.

 

Now in Office 365, emails will have 2 filter tabs, Focused and Other. Important emails are going to appear in the Focused tab, and other emails will appear the other tab clearly. Now a lot of questions might come up when using these features, so let's review some of them: 

 

  • How can a user control what emails appear in other and what emails appear in focused tab? 

There are algorithms that teach the application what emails are good enough to appear in the Focused tab, so once a user moves an email from the Other tab to the Focused tab, Outlook will know that this email source is important for the user, and it'll make sure to make upcoming emails from this source appear in the Focused tab.

 

  • Can a user disable this whole functionality in his Outlook application?

Yes, you can do so by selecting the filter dropdown beside the tabs, and unchecking the option to "Show Focused Inbox", as shown in the image below: 

Focused Other 
Filter 
Next: No events for the ne 
V All 
Filter 
no-reply@sharepoi 
Raed Ibrahim mentioned y 
Raed Ibrahim: Hey @Moha 
Last week 
Microsoft 
Changes coming to Power 
Find the version that's best f 
Microsoft Online Se 
Unread 
To me 
Flagged 
Mentions 
Sort by 
Show as 
V Show Focused Inbox 
View your Office 365 Ente

 

 

Now let's have a look at this scenario, let's say you're working on a project inside SharePoint online, and one of your colleagues mentions you in the newsfeed inside that project portal, like the following image: 

 

Newsfeed (9) 
Raed Ibrahim 
Hello @Mohamed D«halli I am excited to start on this project What's the plan? 
A few seconds ago Like Reply

 

You're going to receive an email from: no-reply@sharepointonline.com,  But .. That email is going to appear only under the Other tab, and here's the catch, you won't receive notifications for emails that appear under the Other tab. By notifications I mean, you won't get notified when you're working in Office 365 that you received a new email: 

 

Undo 
? Mohamed Dernalli 
Notifications 
Nothing new right now

 

Remember that the newsfeed web part only sends emails when you're mentioned. 

 

So how do you solve this? You can't just ask each employee to disable the Focused functionality. You have 2 options in this case, either tell Exchange Online to route all emails from no-reply@sharepointonline.com to the Focused tab, or you can just disable the Focused inbox functionality on the tenancy level. Here's how we can do that: 

 

 

Go to your Office 365 Exchange admin center, and from the left navigation, click "mail flow". Click the + sign to add a new rule: 

 

permissions 
compliance management 
organization 
protection 
mail flow 
mobile 
public folders 
unified messaging 
Create a new rule... 
Apply rights protection to messages... 
ere are no Iti 
Apply disclaimers... 
Bypass spam filtering... 
Filter messages by size.. 
Generate an incident report when sensitive information is detected... 
Modify messages... 
Restrict managers and their direct reports... 
Restrict messages by sender or recipient... 
Send messages to a moderator... 
Send messages and save a copy for review...

 

 

A new window will appear, that looks like this: 

 

new rule 
Name: 
*Apply this rule if... 
Select one 
*Do the following„. 
Select one 
Properties of this rule: 
Audit this rule with severity level: 
Not specified 
Choose a mode for this rule: 
@ Enforce 
O 
Test with Policy Tips 
O 
Test without Policy Tips 
More options... 
Riahts Manaaement Services (RMS) is a premium feature that requires an Enterorise Client Access License (CAL) or a RMS 
Save 
Cancel

 

 

 

 

Give the rule a name, let's say: "Other to Focused Emails Routing", then choose "The recipient address includes…" and click "Enter words…" and add the address you want to appear under Focused tab for all users, in this case no-reply@sharepointonline.com, then click the + sign and hit OK. 

 

 

specify words or phrases 
Cancel

 

 

 

Then go all the way down and click "More options…":  

 

new rule 
Name: 
*Apply this rule if... 
Select one 
*Do the following„. 
Select one 
Properties of this rule: 
Audit this rule with severity level: 
Not specified 
Choose a mode for this rule: 
@ Enforce 
O 
Test with Policy Tips 
O 
Test without Policy Tips 
More options... 
Riahts Manaaement Services (RMS) is a premium feature that requires an Enterorise Client Access License (CAL) or a RMS 
Save 
Cancel

 

 

In the "Do the following…" dropdown list, choose: Modify the message properties > set  a message header

 

the following„. 
Select one 
Select one 
Forward the message for approval.„ 
Redirect the message to.„ 
Block the message„. 
Add recipients„. 
Apply a disclaimer to the message... 
Modify the message properties.„ 
Modify the message security„. 
Prepend the subject of the message with.„ 
Notify the sender with a Policy Tip... 
Generate incident report and send it to„. 
Notify the recipient with a message.. 
remove a message header 
set a message header 
apply a message classification 
set the spam confidence level (SCL)

 

 

 

Set the header to: X-MS-Exchange-Organization-BypassFocusedInbox  and the value to true. So the final result should be: 

 

new rule 
Name: 
Other to Focused Emails Routing 
*Apply this rule if... 
The recipient address includes„. 
add condition 
*Do the following„. 
Set the message header to this value.. 
add action 
Except if... 
add exception 
Properties of this rule: 
Audit this rule with severity level: 
Not specified 
A for this 
Set the message header 'X-MS-Exchange-Organization- 
BypassFocusedInbOx' to the value •Enter text 
Save 
Cancel

 

 

Click save, and that's it. You can wait for a couple of minutes, and then test it. Upcoming emails will be delivered to the Focused tab, and you will receive notifications.

 

 

 

The other option would be to disable the Focused inbox functionality for all users in the tenancy, which leaves you with PowerShell. Once you connect to Exchange Online using PowerShell, you can run the following 2 commands: 

 

Get-OrganizationConfig

Set-OrganizationConfig -FocusedInboxOn $false

 

 

I prefer doing the first approach, and just routing the important emails to users' Focused tab, and give them the freedom to have it if they need. 

 

 

 

 

 

 

 

Customizing Visual Studio Code

Many developers are using Visual Studio Code recently, especially open source developers who are enjoying its features, but some people don’t like the font (Monaco) that comes by default with Visual Studio Code, or maybe they want to use bash commands in terminal. The good thing is, you can customize Visual Studio easily, because Visual Studio Code was built in JavaScript, so in order to customize it, you can modify a JSON file that comes with it. You can open the settings file by going to File > Preferences > Settings, or by clicking Control + , 

 

 

It’ll open a JSON file where you can customize many things, let’s say that we want to use bash commands inside of VSCode , to do this make sure you have bash installed, if not, the easiest thing to do is to go to: https://git-scm.com/downloads  and download the one for your OS. 

Once bash is installed, you’re ready to customize VSCode to use it instead of command prompt. To do this, add this line in VSCode’s settings.JSON file: 

"terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe",

 

So your file would look like this

 

 

Note that the value on the right side is the path to the bash executable file. Now if you click Control + ` (backtick), the terminal will appear, and you will see bash.exe as the default tool to write your commands: 

 

 

Let’s have another scenario, let’s say you want to increase the font size, you add something like this: 

"editor.fontSize": 17

 

Now let’s try to change the font-family, to do so, add this: 

"editor.fontFamily": "Lato"

 

So your file would look like this: 

 

 

Now you’ll wonder, how can you know which fonts are available on your OS? For Windows you can execute these 2 commands in PowerShell: 

[System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")

(New-Object System.Drawing.Text.InstalledFontCollection).Families

It will list all fonts you can use. Want to have extra fonts? You can get new ones from https://fonts.google.com , after you download your font, you will have a font.zip file, extract it and you’ll see the fonts you downloaded as font-name.ttf. Right click on the font name and choose install.. and that’s it! 

 

I hope this gave you an idea on how to customize VSCode to suite your needs, it’s an awesome editor and it’s worth considering when developing your applications. 

 

 

Cool HTML5 stuff to try out

I’ve been busy lately with changing work and working on some projects, but I would like to share with you some nice HTML5 ideas that may inspire you and give your better understanding into what HTML5 is now capable of doing:

Make a wind for your Lion

Keyboard with sounds

Pomodoro Timer  (Just like some of Chrome’s Apps)

CSS Logo Animation

That would give you some ideas on what can be done with HTML5, CSS3 alone, without the need for custom development. Interesting how we can use these techniques now to build fancy stuff on top of SharePoint either online or on premises with the capabilities now available to us to leverage these techniques.

 

 

ReadOnly Vs. Hidden in FieldRef

Ever wanted to know the difference between the “ReadOnly” and “Hidden” attributes for the FieldRef? If your answer was yes, then keep reading..

You may get confused when you try to set the properties for a field in case you want to reference it in a content type, basically you use FieldRef to reference fields in your content type, then you may wonder when to use the “ReadOnly” and “Hidden” attributes.

Similarities:

The reason that makes you consider these attributes is that if you want to hide the item from the NewForm.aspx page. Both will hide your column from this page.

Differences:

The difference here is that “Hidden” will hide your field completely from SharePoint, you will be able to use this field in code though (so you may use it like a property for the content type to store specific values that won’t be shown in the browser), but you won’t see it in browser, you won’t even be able to see the field when you want to modify the view for the current list, it’s Hidden (as its name says!).

ReadOnly will hide the column from the NewForm.aspx page (so it’s a ReadOnly), but you can always modify the list’s view to show this field. So it’s not Hidden 100%.

So never use Hidden in case you want to be able to view the field later in the list!

That was a quick tip that would clear things out for some people out there!

ng-show (or ng-hide) vs. ng-if

Here’s a fact I have found during my work on a SharePoint add-in with AngularJS, you might have read that ng-show does a similar work as ng-if in case you need to hide or show some markup on your page depending on specific condition, so ng-show and ng-if will both do the work, but with slight difference .. or is it a big difference?

The common thing that’s known about the difference between ng-show and ng-if is that, ng-show and ng-hide both will add the styling to change the display of the element to be “none”, so by changing the css for the element and changing the display property, ng-show will hide or show the element. The difference with ng-if is that it will remove the element itself from the markup if the condition is not met, and will return a clone of this element when the condition is met… But that’s not the only difference as well, and not the important difference..

What caught my attention is a difference that’s related to performance. Imagine you have a  table with many rows in your page, with checkbox that’s when checked will view an image related to the row. The thing is, if you’re using ng-show with an expression that evaluates to true/false, all images will always be downloaded in your browser, but you will not see them as they’re going to be hidden because the checkbox is not checked yet. However, when you use ng-if and it evaluates to false by default because the checkbox is not checked, the image will not be downloaded until you check the checkbox, which will be better for browser’s performance (Imagine if you have a repeating section with 100, if you use ng-show, all images will be downloaded to your browser right away, but if you use ng-if, only images that you check will be downloaded).

I hope this helps someone out there with their Angular work as it helped during the Add-in I was working on!

Update items that use Managed Metada column when a term is updated

If you worked with Managed Metadata columns in SharePoint, and tried to change the term’s value in the term store you will notice that the value of the new term is not reflected in your lists, this is a common problem with Managed Metadata, but not a problem at the same time.

The reason for this is, the terms used by the site collection are stored in a hidden list inside the site collection, it’s similar to the list used by variation to synchronize between source sites and target sites when using variation in SharePoint.

All what we have to do in this case is to call the method SyncHiddenList,

public static void SyncHiddenList(SPSite site)

As you see from the definition, we need to pass a parameter of our current site collection, and once it’s called, it will update all of your terms inside lists and libraries.

Error occurred in deployment step ‘Recycle IIS Application Pool’: Cannot connect to the SharePoint site

One of the frustrating problems that you might face while developing SharePoint applications is some of the errors that you really don’t know how to troubleshoot, or where to start your investigation, one of the errors I had is the following:

Error occurred in deployment step ‘Recycle IIS Application Pool’: Cannot connect to the SharePoint site: << Site Collection URL >>. Make sure that this is a valid URL and the SharePoint site is running on the local computer. If you moved this project to a new computer or if the URL of the SharePoint site has changed since you created the project, update the Site URL property of the project.

For this error, my environment was 1 SharePoint development server connected to separate SQL server, I was assigned as the farm administrator, and the local administrator on the SharePoint server, but the problem is getting this error once you try to deploy using visual studio 2010, the solution here is that the user deploying using visual studio to have db_owner permission on the content database for the web application.