Showing posts with label sharepoint 2010. Show all posts
Showing posts with label sharepoint 2010. Show all posts

Tuesday, 15 September 2015

Creating Lookup column from Visual Studio 2012/2013

How to add the lookup column from the Visual Studio 2012 /2013 UI.

  1. Create the lookup column in the Visual Studio UI like below

  2. Go to the properties of the column(select column and press F4) and update the List and ShowField properties with the Target List URL and Column Name to be targeted.

Friday, 11 September 2015

Host Named Site Collection

Host-named site collections enable you to assign a unique DNS name to site collections for example http://MysiteA1.sharepoint.com. 

Host-named site collections can be created only through the Powershell command.


$web= Get-SPWebApplication "http://webApplication URL under which HNSC needs to be created"

New-SPSite "http://MySiteA1.Sharepoint.com" -OwnerAlias "Domain\UserName" -HostHeaderWebApplication $web -Name "MySiteA1"

This should ideally create your Host Named Site Collection. 

Sometimes it may give a warning on the powershell window like below



WARNING: The port specified for the new host header site does not match any known bindings in the specified Web Application. The new site will not be accessible if the Web Application is not extended to an IIS Web Site serving this port.


  1. Go to IIS Manager (type inetmgr from Run)
  2. Find the web application to which we have added the site collection.Right click on it and select Bindings


  3. Click "Add"  bindings to make an entry
  4. Click OK
  5. Open hosts file.(Type drivers from Run, within etc folder)
  6. Add an entry to the hosts for the site collection like below
  7. You will be able to browse your site after giving the URL(You may need to select the template). 
NOTE: If you are prompted credentials  again and again without allowing you login then you will have to disable loop back checking. 


Wednesday, 4 March 2015

Retrieving Server date in SharePoint using client side object model

Recently I came across a requirement that I had to create folder structure in SharePoint list in the hierarchy of CurrentYear\Current Month\DateFolder. The challenge was that we need to achieve this from the client side object model (JSOM).We were not having any access on the Server Object model and there was no hidden control on the master page also which contained the date. We could not rely on the client side date as the user will be logging in from across the globe and there could be chance wrong system timing. These were all payroll details that we cannot let the items go into the wrong folder also.

                So we needed some mechanism by which I can retrieve the server date through JavaScript. All searches suggested for adding some hidden control in the master page or adding a hidden webpart with server code in it.

                Then I found that the “Calendar” which pops out on the date picker control is actually an iFrame i.e. there is actually a calendar page in Layouts folder, found out the page URL through the developer tool. Then again with the help of developer tool I found there is a "<td>" with class name “.ms-picker-footer” which contains today’s date. So now the answer to my problem was simple write a JQuery Load method to fetch the date value from that TD and pass it to JavaScript Date() method.
The calendar page is available in the following URL : /_layouts/iframe.aspx?&cal=1&lcid=2057&langid=2057
 
The iFrame.aspx  page takes the parameters language ID and LCID as query string and the page will provide you the date object in your desired format. I have used the following JQuery code to retrieve the server date.

function GetServerYear() {
    $.get("/_layouts/iframe.aspx?&cal=1&lcid=2057&langid=2057", function (data) {
        var objframe = $(data).find(".ms-picker-footer").find('a:first');
        var returnedYear;
 
        if (Boolean(objframe) && objframe.length > 0) {
            try {
                if (objframe[0].innerText != undefined) {
                    returnedYear = new Date(objframe[0].innerText);
                }
                else {
                    returnedYear = new Date(objframe[0].innerHTML);
 
                }
            }
            catch (err) {
                try {
                    if (objframe[0].innerText != undefined) {
                        returnedYear = new Date(objframe[0].innerText);
                    }
                    else {
                        returnedYear = new Date(objframe[0].innerHTML);
 
                    }
                }
                catch (err1) {
                    returnedYear = (new Date());
                }
            }
        }
}