Monday, 12 October 2015

Missing "Sign in as Different User" option in SharePoint 2013

If you are missing "Sign in as Different User" option in SharePoint 2013, here are few solutions:

Temporary Solutions:

1)Change the siteurl with yours and it will ask you for the new username and password

http://siteurl/_layouts/closeConnection.aspx?loginasanotheruser=true

Keep in mind first option may not work in some browsers and ie10

2) Open internet explorer by  using "run as different user" option  (Shift+ right click) by entering the username and password that you like

Permanent Fix:


1) Open welcome.ascx file. Below is the path of file:
 C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\TEMPLATE\CONTROLTEMPLATES\welcome.ascx

2) Put this code in welcome.ascx page

<SharePoint:MenuItemTemplate runat="server" ID="ID_LoginAsDifferentUser"

Text="<%$Resources:wss,personalactions_loginasdifferentuser%>"

Description="<%$Resources:wss,personalactions_loginasdifferentuserdescription%>"

MenuGroupId="100"   Sequence="100"   UseShortId="true"   />

Thursday, 8 October 2015

Script Block control Error

I was creating a materpage when I got following error on publishing my masterpage:

CS0030: Cannot convert type "Microsoft.SharePoint.Webcontrols.Scriptblock" to "System.Web.UI.IAttributeAccessor".



The solution of this error was hidden in warning of debug.When I check the content of my masterpage I found some extra properties added to ScriptBlock tag. My tag looked like below:

<SharePoint:ScriptBlock runat="server" __designer:Preview="&lt;script
type=&quot;text/javascript&quot;&gt;// &lt;![CDATA[
var g_Workspace = &quot;s4-workspace&quot;; // ]]&gt;
&lt;/script&gt;" __designer:Values="&lt;P N=&#39;ID&#39; T=&#39;ctl09&#39; /&gt;&lt;P
N=&#39;Page&#39; ID=&#39;1&#39; /&gt;&lt;P N=&#39;TemplateControl&#39;
ID=&#39;2&#39; /&gt;&lt;P N=&#39;AppRelativeTemplateSourceDirectory&#39; R=&#39;-
1&#39; /&gt;"></SharePoint:ScriptBlock>

I make it simple like below and my page was working like a charm.

<SharePoint:ScriptBlock ID="ScriptBlock2" runat="server" ></SharePoint:ScriptBlock>

I was working on a user control when I was encountered with below error:

The Page allows a limit of 11 dependency, and that limit has been exceeded.

Dependency Error


Here is the solution for this issue:

1) Go to IIS manager.Choose your site, right-click and select explore.
2) You will find web.config file when you explore your site.Take backup of web.config file
3) Modify web.config as below.

  • Find DirectFileDependencies in web.config 
  • Set DirectFileDependencies="20"
  • Save the file.
4) Refresh the page.

Country Table SQL Script

Recently I was asked to create three tables of country, state and city of world. I thought this data will be useful to every one. Here is my script for Country table. I will add others soon...

CREATE TABLE [dbo].[Country](
[ID] [int] IDENTITY(1,1) NOT NULL,
[CountryName] [nvarchar](100) NOT NULL
) ON [PRIMARY]

GO
SET IDENTITY_INSERT [dbo].[Country] Off 

GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Afghanistan')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Albania')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Algeria')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'American Samoa')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Andorra')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Angola')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Anguilla')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Antarctica')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Antigua And Barbuda')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Argentina')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Armenia')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Aruba')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Australia')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Austria')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Azerbaijan')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Bahamas')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Bahrain')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Bangladesh')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Barbados')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Belarus')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Belgium')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Belize')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Benin')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Bermuda')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Bhutan')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Bolivia')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Bosnia And Herzegowina')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Botswana')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Bouvet Island')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Brazil')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'British Indian Ocean Territory')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Brunei Darussalam')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Bulgaria')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Burkina Faso')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Burundi')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Cambodia')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Cameroon')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Canada')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Cape Verde')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Cayman Islands')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Central African Republic')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Chad')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Chile')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'China')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Christmas Island')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Cocos (Keeling) Islands')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Colombia')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Comoros')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Congo')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Cook Islands')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Costa Rica')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Cote D''Ivoire')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Croatia (Local Name: Hrvatska)')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Cuba')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Cyprus')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Czech Republic')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Denmark')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Djibouti')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Dominica')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Dominican Republic')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'East Timor')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Ecuador')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Egypt')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'El Salvador')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Equatorial Guinea')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Eritrea')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Estonia')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Ethiopia')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Falkland Islands (Malvinas)')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Faroe Islands')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Fiji')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Finland')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'France')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'French Guiana')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'French Polynesia')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'French Southern Territories')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Gabon')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Gambia')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Georgia')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Germany')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Ghana')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Gibraltar')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Greece')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Greenland')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Grenada')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Guadeloupe')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Guam')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Guatemala')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Guinea')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Guinea-Bissau')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Guyana')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Haiti')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Heard And Mc Donald Islands')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Holy See (Vatican City State)')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Honduras')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Hong Kong')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Hungary')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Iceland')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'India')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Indonesia')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Iran (Islamic Republic Of)')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Iraq')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Ireland')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Israel')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Italy')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Jamaica')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Japan')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Jordan')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Kazakhstan')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Kenya')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Kiribati')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Korea, Dem People''S Republic')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Korea, Republic Of')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Kuwait')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Kyrgyzstan')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Lao People''S Dem Republic')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Latvia')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Lebanon')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Lesotho')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Liberia')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Libyan Arab Jamahiriya')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Liechtenstein')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Lithuania')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Luxembourg')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Macau')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Macedonia')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Madagascar')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Malawi')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Malaysia')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Maldives')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Mali')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Malta')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Marshall Islands')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Martinique')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Mauritania')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Mauritius')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Mayotte')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Mexico')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Micronesia, Federated States')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Moldova, Republic Of')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Monaco')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Mongolia')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Montserrat')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Morocco')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Mozambique')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Myanmar')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Namibia')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Nauru')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Nepal')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Netherlands')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Netherlands Ant Illes')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'New Caledonia')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'New Zealand')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Nicaragua')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Niger')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Nigeria')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Niue')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Norfolk Island')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Northern Mariana Islands')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Norway')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Oman')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Pakistan')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Palau')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Panama')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Papua New Guinea')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Paraguay')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Peru')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Philippines')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Pitcairn')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Poland')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Portugal')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Puerto Rico')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Qatar')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Reunion')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Romania')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Russian Federation')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Rwanda')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Saint K Itts And Nevis')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Saint Lucia')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Saint Vincent, The Grenadines')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Samoa')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'San Marino')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Sao Tome And Principe')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Saudi Arabia')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Senegal')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Seychelles')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Sierra Leone')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Singapore')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Slovakia (Slovak Republic)')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Slovenia')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Solomon Islands')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Somalia')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'South Africa')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'South Georgia , S Sandwich Is.')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Spain')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Sri Lanka')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'St. Helena')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'St. Pierre And Miquelon')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Sudan')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Suriname')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Svalbard, Jan Mayen Islands')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Sw Aziland')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Sweden')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Switzerland')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Syrian Arab Republic')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Taiwan')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Tajikistan')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Tanzania, United Republic Of')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Thailand')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Togo')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Tokelau')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Tonga')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Trinidad And Tobago')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Tunisia')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Turkey')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Turkmenistan')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Turks And Caicos Islands')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Tuvalu')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Uganda')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Ukraine')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'United Arab Emirates')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'United Kingdom')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'United States')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'United States Minor Is.')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Uruguay')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Uzbekistan')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Vanuatu')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Venezuela')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Viet Nam')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Virgin Islands (British)')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Virgin Islands (U.S.)')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Wallis And Futuna Islands')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Western Sahara')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Yemen')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Yugoslavia')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Zaire')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Zambia')
GO
INSERT [dbo].[Country] ([CountryName]) VALUES (N'Zimbabwe')
GO
SET IDENTITY_INSERT [dbo].[Country] OFF
GO

Thursday, 3 September 2015

Find element using jQuery.

If you want to find html element using jquery this post can be helpful.


  • If you're finding by Contains then it'll be like this

    $("input[id*='ElementID']")

  • If you're finding by Starts With then it'll be like this

    $("input[id^='ElementID']")

  • If you're finding by Ends With then it'll be like this

     $("input[id$='ElementID']")

  • If you want to select elements which id is not a given string

    $("input[id!='ElementID']")

  • If you want to select elements which id contains a given word, delimited by spaces

     $("input[id~='ElementID']")

  • If you want to select elements which id is equal to a given string or starting with that string followed by a hyphen

     $("input[id|='ElementID']")

Friday, 31 July 2015

Responsive Design

Increase of portable device usage requiring dynamic design changes for static site. Currently I have faced some issue with such concept. My requirement was to display a table on a page and make it look dynamic.

Here are some methods that I used to do it.

1) Using pure CSS :

You need to use media queries to make content dynamic. here is my code sample:

// for device Apple iPhone 5 or less, Samsung Galaxy S3 mini or less and Microsoft Lumia phones
@media (max-width: 320px) {
#docsTable{ 
max-width:320px;
}
}

// for device Apple iPhone 6,LG G3,LG Optimus G,Samsung Galaxy Note 2,Samsung Galaxy S3- S5,Samsung Galaxy Nexus

@media (max-width: 480px) {
#docsTable{ 
max-width:480px;
}
}

//for Apple iPad series
@media (max-width: 768px) {
#docsTable{ 
max-width:768px;
}
}

For other device width information  click here

But the problem occurs when the device has slightly smaller or larger width. It displays scroll which is not user friendly. Here is a way to handle such thing:

2) using Javascript

In this method we calculate the width by device's width and add width css to control at display time.

<script type="text/javascript">
$(document).ready(function() {
    // run test on initial page load
    checkSize();

    // run test on resize of the window in browser. Also need for screen rotation.
    $(window).resize(checkSize);
});

//Function to the css rule
function checkSize(){
    if(window.innerWidth < 768)
{
var thisObject = $("#docsTable");
var actualWidth = window.innerWidth - 50;
thisObject.css("max-width",actualWidth+"px");
}
});
}
</script>

Monday, 6 July 2015

Display Other site collection List data in current site collection using Client object modal.

A very bad dream in SharePoint 2013 is to "Display Other site collection List data in current site collection" as SharePoint Designer 2013 has deprecated data view web part and content search web part does not give look and feel as we wanted. It might be simple but I will update my self and this blog if I get success in near future with it.

Here is the sample code to display data from other site collection:

1) You need to add a web part page.  Add a "Content Editor Web part " in this page. In this paste below code with your changes.

<div>
   <!-- Table -->
  <table id="docsTable">
    <thead>
    <tr>
<th>ID</th>
<th>Title</th>
<th>Modified</th>
</tr>
</thead>
  </table>
</div>


<script language="javascript" type="text/javascript">
$(document).ready()
{
var folderUrl = document.getElementById('folderpath').value;
var url =document.getElementById('sitepath').value +"/_api/Web/GetFolderByServerRelativeUrl('" + folderUrl + "')?$expand=Folders,Files";


 // Get Folders and Files in single call. You can try using ajax call too. I have tried it but I was forced to call method multiple time.

$.getJSON(url,function(data,status,xhr){

 // Get Folders

    for(var i = 0; i < data.Folders.length;i++){      
        $('<tr>').append(
        $('<td>').html("data.Folders[i].ID"), // Append ID
        $('<td>').html("<a href='"+data.Folders[i].ServerRelativeUrl+"' target='_blank'>"+data.Folders[i].Name+"</a>"), // Apend Name. Click redirect to specific Item
        $('<td>').text(data.Folders[i].TimeLastModified.substring(0, 10))).appendTo('#docsTable'); //Append modified date.
    }

 // Get Files

    for(var i = 0; i < data.Files.length;i++){      
        $('<tr>').append(
        $('<td>').html("data.Files[i].ID"),  // Append ID
        $('<td>').html("<a href='"+data.Files[i].ServerRelativeUrl+"' target='_blank'>"+data.Files[i].Name+"</a>"), // Apend Name. Click redirect to specific Item
        $('<td>').text(data.Files[i].TimeLastModified.substring(0, 10))).appendTo('#docsTable');//Append modified date.
    }
})

}

This is a sample code. You can Add some more functionality like paging, sorting or can change fields as per your need.

JavaScript check if file exist at URL or not.

I was trying simple things lately with client side object modal. Here is one of the main issue I have face

"How to check if image / file exist at given path?"

I have tried using .done,.fail,.success,.complete and many more tricks that I could use. Even I tried Try.. Catch .. finally. But the real issue was if file does not exist at URL it will give exception 404. But not throw it so it won't be cached. Finally I came across a method shown below which gives me 404 error but will return result.

Answer: 

function doesFileExist(urlToFile)
{
    var xhr = new XMLHttpRequest();
    xhr.open('HEAD', urlToFile, false);
    xhr.send(); // Here it will generate 404
   
    if (xhr.status == "404") {
        return false;
    } else {
        return true;
    }
}

Calling :

if (doesFileExist(filePath)) {
            // yay, file exists!
        } else {
   // oops, file not exist!
}

Wednesday, 3 June 2015

Error - "Sorry, apps are turned off. If you know who runs the server, tell them to enable apps."

you will see this error when you try to add SharePoint Hosted app :

Sorry, apps are turned off. If you know who runs the server, tell them to enable apps.

Solution:

In order to install an App from the App Store you must setup an isolated App Domain, this is because Apps from the store deploy to their own app domain and run under a separate process from your SharePoint sites.

If your SharePoint site uses the DNS alias http://sharepoint.contoso.com you could have *.apps.contoso.com as your app domain.

http://www.sharepointalex.co.uk/index.php/2012/11/enabling-sharepoint-2013-apps/

How to: Set up an on-premises development environment for apps for SharePoint

http://msdn.microsoft.com/en-us/library/fp179923(v=office.15).aspx

The Subscription Settings service and corresponding application and proxy needs to be running in order to make changes to these settings.

I was working on hosted app when I encountered below error:

The Subscription Settings service and corresponding application and proxy needs to be running in order to make changes to these settings.


Solution:

Copy and paste below script in SharePoint Management Shell.

$acc = Get-SPManagedAccount <AccountName>
$appPool = New-SPServiceApplicationPool -Name "<Application pool name>" -Account $acc
$app = New-SPSubscriptionSettingsServiceApplication –ApplicationPool $appPool –Name "Subscription Settings Service Application" –DatabaseName <Database name>
$proxy = New-SPSubscriptionSettingsServiceApplicationProxy –ServiceApplication $app

Where
   Replace your <AccountName> with managed account
   Replace your <Application pool name> with Subscription Settings Service Apppool

   Replace your <Database name> with SPMT_Settings_Service_DB  

Reference:
https://technet.microsoft.com/en-us/library/fp161236(v=office.15).aspx