Skip to main content

Posts

Showing posts from 2013

SharePoint 2013 - Unexpected response from server. The status code of response is '0'. The status text of response is ''.

I found this strange error when i work with SharePoint JavaScript Object modal (JSOM) . By searching i found that this is due to anonymous permission problem caused by Ajax calls. In my case i put button tag in to my page which is causing this error. I changed the button tag to input tag and it worked perfectly.

Restore Site Collection in SharePoint 2013

I have been difficult situation that i accidently delete a SharePoint site collection and create a site collection in a same URL. As i created a site collection in a same URL i thought  it can not be restored. But there is a power shell command which saved my ass. First you need to run Get-SPDeletedSite command to find out GUID of the deleted site. Now you can take the SiteId of the deleted site. Reference: http://technet.microsoft.com/en-us/library/hh286316.aspx Then you need to make sure no site is available in the restore path Then execute the following command to restore the site collection. Restore-SPSite –Identity SiteId Reference: http://technet.microsoft.com/en-us/library/ff607788.aspx

SharePoint 2013 Maintenance Notification

SharePoint 2013 contains a SPMaintenaceWindow class which can use to give notifications to end users scoped to SharePoint content database. This is a simple PowerShell script you need to execute. Ex:- Enable Notification $maintenanceStartDate = "11/29/2013 08:00:00 AM" # Date when the maintenance will start $maintenanceEndDate = "11/30/2013 02:00:00 PM" # Date when the maintenance will stop $notificationStartDate = "11/28/2013 06:00:00 AM" # Date when the message will start being displayed $notificationEndDate = "11/30/2013 02:00:00 PM" # Date when the message will stop being displayed $maintenanceLink = "" # This link will only appear if the maintenance duration is defined. $maintenanceType = "MaintenancePlanned" # OPTIONS ARE: MaintenancePlanned | MaintenanceWarning $readOnlyDays = 1 # duration days $readOnlyHours = 6 # duration hours. $readOnlyMinutes

JSOM Practices in SharePoint @ SharePoint Forum

JSOM and java script practices from Melick Baranasooriya

How to Check User permission for the web, list or SharePoint Item in SharePoint JavaScript Object Model

Normally we need to perform tasks such as Does current user is admin on the site Does current user has list edit permissions etc SharePoint provides a method called doesUserHavePermissions to perform that. First of all we need to know how SharePoint defines User roles by assigning permission levels   such as Full Control, Contributor , design and etc. For an example site admin is assigned by Full Control which is a composite of few permission items we called as permission kind. Full Control - http://office.microsoft.com/en-001/windows-sharepoint-services-help/permission-levels-and-permissions-HA010100149.aspx You can get all permission kind by http://msdn.microsoft.com/en-us/library/ee556747(v=office.14).aspx Example One Assume that we want to check whether current user is a admin of the site. For that we need to check user has  manageWeb permission kind. ( actually we need to check other permission kinds assign to full control as well but if user has manage web it is mo

Apps for SharePoint 2013 - Session @ University of Kelaniya

Introduction and development guide for SharePoint 2013 apps on 31st Nov 2013. Apps for SharePoint 2013 from Melick Baranasooriya

How to disable Custom Errors in Layout Pages / Application Pages in SharePoint 2013

For disable custom errors you need navigate to C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\TEMPLATE\LAYOUTS and Open the web.config and make the CustomErrors off <customErrors mode="Off" />

Get List Item By Id with specified fields in SharePoint JavaScript Object Model

var ctx = new SP.ClientContext.get_current(); var web = ctx.get_web();   //Geting reference to the list var olist = web.get_lists().getByTitle( 'Configs' ); var oitem = olist.getItemById(1); //get Title,id,ConfigItem fields ctx.load(oitem, "Title" , "Id" , "ConfigItem" ); ctx.executeQueryAsync( function () {   alert(oitem.get_item( "Title" )); alert(oitem.get_item( "ConfigItem" ));   }, function (a, b) { alert(b.get_message()); });

SharePoint Training @ Pyxle

Audience : 15 Members

Format Text Out as a Table (Format-Table) in Power Shell

Format-Table in a powerful command that you can use to format your output. output can be a console or a file out. Format-Table working with object or a object collection. For an example If you have a object collection from your code you can out put as a table. Get-SPSite -Limit All | Format-Table –AutoSize -AutoSize will be use to format columns with depending of screen size. But if you are working with long width tables you better use Out-String -Width 4000 with output pipe. (4000 is a character count in horizontal, You can mention any suitable value ) Ex:- Get-SPSite -Limit All| Format-Table –AutoSize | Out-String -Width 4000 You can use Format-Table with a single object as well. Ex:- With all columns   $objAverage = New-Object System.Object $objAverage | Add-Member -type NoteProperty -name Col1 -value "saman" $objAverage | Add-Member -type NoteProperty -Name Col2 -Value 23423   $objAverage | Format-Table –AutoSize Ex:- With mentioned columns $objAverage = New-Obje

Get SharePoint Feature by Name and Execute for all site collections

This is a simple script for day today works :) This script will find a feature that contains name like “OpenIn” and activate for entire site collections. Enable Feature for All Site Collections $feature = Get -SPFeature | where { $_.DisplayName - like "*OpenIn*" }   $featureId = $feature.Id Get -SPSite -limit ALL |foreach{ Enable-SPFeature $featureId -url $_.URL -confirm:$ false } This script will find a feature that contains name like “OpenIn” and deactivate for entire site collections. Disable Feature for All Site Collections $feature = Get -SPFeature | where { $_.DisplayName - like "*OpenIn*" }   $featureId = $feature.Id Get -SPSite -limit ALL |foreach{ Disable-SPFeature $featureId -url $_.URL -confirm:$ false }

Working with client side relative Url Tokens in SharePoint 2010/2013

Most of the time we are having problems with Getting relative site collection URL in client side Getting relative Layout URL in client side Getting web site URL in client side when we are developing SharePoint applications. (for an example Creating a custom master page and providing links to content inside the SharePoint). If we are working with SharePoint  Standard or Enterprise we can  use < link rel= "stylesheet" type= "text/css" runat= "server" href= "<% $SPUrl:~sitecollection/Style%20Library/mystyle.css %>" /> But to work with SPUrl you need the control to be server control ( runat = server ). Other Possible Url tokens are ~site/ ~sitecollection/    ~language there are few other undocumented Tokens as well . Other than that you can use _spPageContextInfo JavaScript Objet in all SharePoint versions. <script type= "text/javascript" > function goToLink(link) { location.href = _spPageContextInfo.web

SharePoint 2013 Page Layout Zone Titles and Structure

These zone names are needed when you insert Web Parts programmatically. Header,Footer, 3 Columns Header LeftColumn MiddleColumn RightColumn Footer Full Page, Vertical FullPage Header, Left Column, Body Header LeftColumn Body Header, Right Column, Body Header Body RightColumn Header, Footer, 2 Columns, 4 Rows Header Row1 RightColumn LeftColumn Row2 Row3 Row4 Footer Header, Footer, 4 Columns, Top Rows Header LeftColumn TopRow RightColumn CenterLeftColumn CenterRightColumn Footer Left Column, Header, Footer, Top Row, 3 Columns LeftColumn Header TopRow CenterLeftColumn CenterColumn CenterRightColumn Footer     Right Column, Header, Footer, Top Row, 3 Columns Header RightColumn TopRow CenterLeftColumn CenterColumn CenterRightColumn Footer

MVC4 Session @ SL Air Force

I have hosted a MVC4 introduction and basic development session for Sri Lanka Navy (Head Quarters) behalf of Microsoft Sri Lanka. Audience was pretty good and we had  a more than one our questions and answer session Date : 31 Jul 2013 Attendance : 15 Members

Single Reference JavaScript Pattern for SharePoint 2013 App Development and Web Development (SRJ Pattern by Melick)

I have tried many different ways to properly organized JavaScript in my Developments. When I'm developing I have faced following issues. Each and every place we need to include script files IF one place change we need to change all the pages for references Assume we need to update JQuery  version then we need to change all pages which refers scripts. Thus i thought to work on my pattern with the help of JavaScript Loader to overcome this situation. I have used Head.js to dynamically load JavaScript's. There are few other JavaScript loaders such as RequireJS Head.js ControlJS LABjs I have chosen Head.js because of performance and simplicity you can develop this pattern to work with any JavaScript loader. Head.js supports other css declaration and media queries as well. This pattern can be extended support css loading as well. This is very simple pattern. In here you need to only refer one script in a page and It will take care of loading other scripts for you. S