Wednesday, November 11, 2015

VirtualBox shows only 32 bit guest versions ― and how I fixed it

I recently purchased Lenovo Yoga 500 with 64-bit Windows 10. I installed Oracle VirtualBox on it but was surprised to find that I could only install 32-bit versions of OS on it. I found this article which suggested toggling Intel (R) Virtualization Technology and Intel (R) VT-d Feature settings in BIOS. But in my laptop I couldn't find this setting. Rather you will find a setting under Configuration tab called Intel Virtual Technology and enable it.



Reboot your system and now try to install OS in VirtualBox and it should now show both 32-bit and 64-bit versions of OS.

Thursday, July 2, 2015

How to sort SharePoint object of SPWeb in SPWebCollection based on Title?

A questioner posed an interesting question on SharePoint StackExchange – how to get all the web sites (SPWeb) in SharePoint and sort them alphabetically.

SPSite.AllWebs returns a collection of all web sites that are contained within the site collection. But they seem to be in random order and are not sorted alphabetically based on their Title. Sorting these web sites based on their title is actually pretty easy.

SPSite.AllWebs returns object of SPWebCollection which inherits from IEnumerable<T> interface. This interface has a function called OrderBy using which we can order the SPWeb based on its Title property.

SPWebCollection webColl = site.AllWebs;
// Sort the SPWeb alphabetically based on Title
IEnumerable sortWebColl = webColl.OrderBy(w => w.Title); 
foreach (SPWeb web in sortWebColl) {
    // Code
}

You also need to make sure that you use the following namespaces otherwise it will throw error.

using System.Linq;
using System.Collections;
using System.Collections.Generic;

You can extend the above code snippet to sort based on Description and other properties of SPWeb also.

Wednesday, May 20, 2015

Get appWebUrl and hostUrl in SharePoint Online / Office 365

When you are developing in SharePoint Online / Office 365 you will have to fetch appWebUrl and hostUrl if you want to perform any operation on your lists and libraries. I could find two ways of getting these values.

1. Reading values of SPAppWebUrl and SPHostUrl from query string


When you run your project it opens up the page Default.aspx. The URL of this page looks something like this.


Notice the query string parameters of SPAppWebUrl and SPHostUrl. You can fetch these values via a helper function.

Friday, April 24, 2015

Permission, Permission Level and Permission Policy in SharePoint

Permission, Permission Level and Permission Policy are three very different functionalities yet closely related in SharePoint. This article presents my understanding of what they are and how they work in SharePoint. It has been written with SharePoint 2010 in reference.

Permission


Permission means an action allowing someone to do a particular thing. In SharePoint it means the same. So you have permissions like Add Items, Edit Items, Delete Items and 30 more permissions. Yes, there are in all 33 permissions in SharePoint.

Permissions are divided into three categories.

  • Site Permissions (18) – apply generally across a SharePoint site
  • List Permissions (12) – apply to content in lists and libraries
  • Personal Permissions (3) – apply to content that belongs to a single user

Permissions also depend on other permissions. For e.g. you must be able to open an item to view it. In this way, View Items permission depends on Open permission. Below is the complete list of all the permissions and dependent permissions.

Thursday, April 9, 2015

Disable uppercase menu in Visual Studio

When I started learning SharePoint I came across Visual Studio and its hideous upper case menu.


I don't know what was the reasoning behind this, but in Visual Studio Community 2013 version you turn this off to show more conventional title case menu.

For this go to "Tools > Options". Under "Environment > General" enable the option of "Turn off upper case in menu bar".


And you will get the menu in title case.


Monday, April 6, 2015

Split string in JavaScript using regular expression

JavaScript has split() method which returns array of the substrings based on the separator character used. But you can also split a string using regular expression.

Say you have a credit card number which you want to split in array of four substrings with each substring consisting of 4 digits. For that you would use the match method of string.

var strValue = "1111222233334444";
var splitValues = strValue.match(/(\d{4})(\d{4})(\d{4})(\d{4})/);

// Start looping array from 1st index position as 0
// index position contains the entire parent string
for (var i=1 ; i<splitValues.length ; i++) {
 // Loop through the elements
}

Here, you use the match method and pass it the regular expression of (\d{4})(\d{4})(\d{4})(\d{4}) to split it into four equal substrings of four digits each. One thing to remember here is that the string returned here contains the parent string at the 0 index position and then the split substrings start at 1st position.

There is limitation here though — you need to know the number of characters in the string before hand, which might not be the case always.

Thursday, February 5, 2015

Significance of BaseViewID="0" in schema.xml for SharePoint List Definition

Whenever you create a SharePoint List Definition in Visual Studio the schema.xml file contains two entries for View.

<View BaseViewID="0" Type="HTML" MobileView="TRUE" TabularView="FALSE">

<View BaseViewID="1" Type="HTML" WebPartZoneID="Main" 
      DisplayName="$Resources:core,objectiv_schema_mwsidcamlidC24;" 
      DefaultView="TRUE" MobileView="TRUE" MobileDefaultView="TRUE" 
      SetupPath="pages\viewpage.aspx" ImageUrl="/_layouts/images/generic.png" 
      Url="AllItems.aspx">

Note that one of the views has BaseViewID="0" while other one has BaseViewID="1". The view with BaseViewID set to 1 is the default view with Url set to AllItems.aspx. But the view with BaseViewID set to 0 has no Url attribute set. Any modification for BaseViewID="1" gets reflected on the default view but I couldn’t figure out where the BaseViewID="0" view was being used. Even MSDN documentation is not very clear about it. A bit puzzled about this I posted this question on SharePoint StackExchange and was pointed to this answer which explains the reason for this additional view.

Wednesday, February 4, 2015

Prevent adding duplicates records from predefined data in ListInstance while reactivating its feature

In SharePoint if we have predefined data in ListInstance then deactivating and then reactivating its feature causes the predefined data to created again resulting in duplicates. Say, for e.g. our ListInstance looks something like this.

<ListInstance ...>
  <Data>
    <Rows>
      <Row>
        <Field Name="Title">Record 1</Field>
      </Row>
      <Row>
        <Field Name="Title">Record 2</Field>
      </Row>
    </Rows>
  </Data>
</ListInstance>

If we deploy this to a SharePoint site and if we deactivate and reactivate its feature then we will have “Record 1” and “Record 2” appear twice. Deactivating and reactivating it again would only create more duplicates.

Monday, January 19, 2015

Curse you Adobe!

Its 2015 and Adobe Reader still asks for system restart when it updates itself. It greets you with a dreadful message after every update:

You must restart your system before using Adobe Reader. Click Restart Now to restart automatically.

This wasn't the first time that I got this message and I am not the only one to question this (by the way this question was asked way back in 2011).

So when I got this popup again some days back, I accidentally clicked on "Restart Now". And my PC restarted itself. With me working on 3 different Word documents and 1 Excel worksheet. With a Ubuntu running in my VM. And it didn't even ask me if I wanted to close my open programs. It simply restarted.

I initially suspected this to be a problem with Windows; that it didn't ask me to close my open programs. So when today I got a couple of updates for my Windows, it again asked me for a restart. This time I opened up a Word document tried to restart to finish installing updates. It showed me message that I have some programs running. I closed my Word document and fired up my VM running Ubuntu. Again the same message.

So it seems to me that Adobe Reader's restart uses some kind of forced restart which does not care about the programs currently running on your PC. And that's why I say —

Curse you Adobe!

Sunday, January 18, 2015

Open command prompt from Windows Explorer in folder path and vice versa

Many a times you have Windows Explorer opened to a folder location and you need Command Prompt to be opened in that same location. Rather than opening Command Prompt and then navigating to the said directory there is a better way.

Hold down Shift key and right-click. Click on “Open command windows here”. This feature seems to have been present since Windows Vista.



Conversely, if you are in your Command Prompt in a specific folder and you want to open that folder in Windows Explorer then simply type in the following command: