Thursday, March 27, 2014

Parsley.js alphabets validation

In Parsley.js there are a lot of biult-in validations , however for alphabets only you should use regular expression .
In my case , for example:

 
    
    

Thursday, August 8, 2013

TFS Build Service failed with HTTP code 404

When you work with VS 2012 and try to open TFS 2010 project, you could be failed with this error message :

"HTTP code 404 : Not Found", in my case clearing the cache worked.

So, what you need is :

Delete all in the folder :

C:\Users\userName\AppData\Local\Microsoft\Team Foundation\4.0\Cache




Sunday, May 5, 2013

In Visual Studio 2012 templates for Microsoft Office 2013 doesn't appear

By default, the Office developer tools in Visual Studio include templates only for Microsoft Office 2010. If you want to develop solutions for Office 2013, you must download the Microsoft Office Developer Tools for Visual Studio 2012, which include project templates for Office 2013. 
Link for download

Monday, January 28, 2013

Saving page in SharePoint Designer gives JavaScript error



When you try to save document in SharePoint designer - the JavaScript error started raising.


I found that it occurred after a cumulative update SharePoint 2010 - KB2597132.

The solution to fixed it was -

1.Copying files:

FORM.JS
INIT.JS
CORE.JS
BFORM.JS
OWS.JS

from an environment where it works to : "../LAYOUTS/1033".

2.Reset the IE settings


Saturday, January 12, 2013

Method not found: 'System.String System.ServiceModel.Activation.Iis7Helper.ExtendedProtectionDotlessSpnNotEnabledThrowHelper(System.Object)'.

After installing Microsoft patch MS13-04[KB 2756920](Security Update for Microsoft .NET Framework 3.5.1 on Windows 7 and Windows Server 2008 R2 - A security issue has been identified that could allow an unauthenticated remote attacker to compromise your system and gain control over it.), our SharePoint Portal was down with the error :
 WebHost failed to process a request. 
 Sender Information: System.ServiceModel.ServiceHostingEnvironment+HostingManager/17653682 Exception: System.ServiceModel.ServiceActivationException: The service '/SecurityTokenServiceApplication/securitytoken.svc' cannot be activated due to an exception during compilation. The exception message is: Method not found: 'System.String System.ServiceModel.Activation.Iis7Helper.ExtendedProtectionDotlessSpnNotEnabledThrowHelper(System.Object)'.. ---> System.MissingMethodException: Method not found: 'System.String System.ServiceModel.Activation.Iis7Helper.ExtendedProtectionDotlessSpnNotEnabledThrowHelper(System.Object)'. at System.ServiceModel.WasHosting.MetabaseSettingsIis7V2.WebConfigurationManagerWrapper.BuildExtendedProtectionPolicy(ExtendedProtectionTokenChecking tokenChecking, ExtendedProtectionFlags flags, List`1 spnList) at System.ServiceModel.WasHosting.MetabaseSettingsIis7V2.WebConfigurationManagerWrapper.GetExtendedProtectionPolicy(ConfigurationElement element) at System.ServiceModel.WasHosting.MetabaseSettingsIis7V2.ProcessWindowsAuthentication(String siteName, String virtualPath, HostedServiceTransportSettings& transportSettings) at System.ServiceModel.WasHosting.MetabaseSettingsIis7V2.CreateTransportSettings(String relativeVirtualPath) at System.ServiceModel.Activation.MetabaseSettingsIis.GetTransportSettings(String virtualPath) at System.ServiceModel.Activation.MetabaseSettingsIis.GetAuthenticationSchemes(String virtualPath) at System.ServiceModel.Channels.HttpChannelListener.ApplyHostedContext(VirtualPathExtension virtualPathExtension, Boolean isMetadataListener) at System.ServiceModel.Channels.HttpTransportBindingElement.BuildChannelListener[TChannel](BindingContext context) at System.ServiceModel.Channels.BindingContext.BuildInnerChannelListener[TChannel]() at System.ServiceModel.Channels.MessageEncodingBindingElement.InternalBuildChannelListener[TChannel](BindingContext context) at System.ServiceModel.Channels.BinaryMessageEncodingBindingElement.BuildChannelListener[TChannel](BindingContext context) at System.ServiceModel.Channels.BindingContext.BuildInnerChannelListener[TChannel]() at System.ServiceModel.Channels.Binding.BuildChannelListener[TChannel](Uri listenUriBaseAddress, String listenUriRelativeAddress, ListenUriMode listenUriMode, BindingParameterCollection parameters) at System.ServiceModel.Description.DispatcherBuilder.MaybeCreateListener(Boolean actuallyCreate, Type[] supportedChannels, Binding binding, BindingParameterCollection parameters, Uri listenUriBaseAddress, String listenUriRelativeAddress, ListenUriMode listenUriMode, ServiceThrottle throttle, IChannelListener& result, Boolean supportContextSession) at System.ServiceModel.Description.DispatcherBuilder.BuildChannelListener(StuffPerListenUriInfo stuff, ServiceHostBase serviceHost, Uri listenUri, ListenUriMode listenUriMode, Boolean supportContextSession, IChannelListener& result) at System.ServiceModel.Description.DispatcherBuilder.InitializeServiceHost(ServiceDescription description, ServiceHostBase serviceHost) at System.ServiceModel.ServiceHostBase.InitializeRuntime() at Microsoft.IdentityModel.Protocols.WSTrust.WSTrustServiceHost.InitializeRuntime() at System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout) at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) at System.ServiceModel.ServiceHostingEnvironment.HostingManager.ActivateService(String normalizedVirtualPath) at System.ServiceModel.ServiceHostingEnvironment.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath) --- End of inner exception stack trace --- at System.ServiceModel.ServiceHostingEnvironment.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath) at System.ServiceModel.ServiceHostingEnvironment.EnsureServiceAvailableFast(String relativeVirtualPath) Process Name: w3wp 

 RESOLUTION: Uninstall KB 2756920

Wednesday, January 2, 2013

Get SPUser Object from SPListItem

Sometimes, you need to get SPUser object(to retrieve email, name,...) , however you have only SPListItem with SPFieldCollection. When you try to retrieve it, for example:


var field = item["user"]


you just get  a string with User ID , like : "123;#"

We need to cast this object to SPFieldUserValue.

This C# code can help us:



public SPUser GetSPUserObject(SPListItem spListItem, String fieldName)
    {
        SPUser spUser = null;
        try
        {
            if (fieldName != string.Empty)
            {
                SPFieldUser field = spListItem.Fields[fieldName] as SPFieldUser;
                if (field != null && spListItem[fieldName] != null)
                {
                    SPFieldUserValue fieldValue = field.GetFieldValue(spListItem[fieldName].ToString()) as SPFieldUserValue;
                    if (fieldValue != null)
                    {
                        spUser = fieldValue.User;
                    }
                }
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
        return spUser;
    }


Saturday, December 29, 2012

SHAREPOINT 2013 – USING “JS LINK”


SharePoint 2013 has a lot new features and functionalities that it can do OOB.
One of these new functionalities is the "JS Link" web part property. With this property you are able to control the rendering of the web part.

This will mostly be used in combination with List/Data View Web Part. So, no more server side XSLT rendering (XSL Link), just client side JavaScript (JS Link).
There is the link to MSDN

Monday, December 17, 2012

Cross Site Content - it's coming in SharePoint 2013

As a lot of programmers who had a problem with cross-site content:how to show data from another site collection,another web application or another farm. All of us can search the internet and find solutions (3rd party, code implementation, etc...). In SharePoint 2013 this problem will be resolved by Cross-Site Publishing. On the official blog of the Microsoft SharePoint Product Group says that the new XSP aggregates a data by the search-based publishing model and a content can be shared across site collections, web apps, and farms. The new concept which introduced in SharePoint 2013 allows to publish lists, libraries, search catalog or variation data. More information is here.

Wednesday, December 12, 2012

Error occurred in deployment step ‘Recycle IIS Application Pool’: The communication object, System.ServiceModel.InstanceContext, cannot be used for communication because it has been Aborted.

The Problem :

"Error occurred in deployment step ‘Recycle IIS Application Pool: The communication object, System.ServiceModel.InstanceContext, cannot be used for communication because it has been Aborted."

The Solution:

Restart  Visual Studio 2010 and the problem should be resolved.

Wednesday, October 31, 2012

Adding a footer to SharePoint v4 MasterPage

I have a simple customized v4 Master Page.
I tried to use "footer" tag to make my footer at bottom of the page.
This is the solution:

This is Contoso Site - Copyright© 2012 Contoso - All Rights Reserved.

Sunday, September 23, 2012

Select custom ribbon tab - jQuery

    I created custom ribbon tab and a button on a page. When  a user press the button on the page, I needed to focus him to the custom ribbon tab. Of course, I used 
_ribbonStartInit("Ribbon.CustomTab", false, null);

but the problem is, after a user changes it to another tab, i.e. "Read" or "Browse" the second pressing doesn't work. Therefore, the solution was - adding SelectRibbonTab() function:

$('img.CustomTabButtonClass').bind('click', function() { 
    
  if (typeof(_ribbonStartInit) == "function")
   {
     try 
     {
       _ribbonStartInit("Ribbon.CustomTab", false, null);
     }
     catch(e)
       {
                  
        }
     SelectRibbonTab("Ribbon.CustomTab", true);
    }
    });

Tuesday, September 11, 2012

CSS: Cursor hand not working in chrome, firefox

The problem is  - cursor "hand" is not a supported style in browsers other than IE.
Instead of it need to use :
cursor: "pointer"

The vertical scrolling bar doesn't work in Chrome browser

Like most of us, I faced this problem when scroll bar doesn't work in Chrome.
After googling, the solution was a jQuery script which I inserted to the master page:



Sunday, August 12, 2012

Create List Definition for Picture Library - C#


If you want to do it in Visual Studio, you're unable to see this definition in the drop down list. However it is very easy to do it:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint; 

namespace Console
{
    class Program
    {
        string listName = "Picture Library";
        string description = "My  Picture Library "; 

        public static void Main(string[] args)
        {
            using (SPSite oSite = new SPSite("http://contoso.com"))
            {
                using (SPWeb oWeb = oSite.OpenWeb())
                {
                    if (oWeb.Lists.TryGetList(listName) != null)
                    {
                        // SPListTemplate class - Used to represent the list definition or a list template 
                        // oWeb.ListTemplates - Used to get the "Picture Library" list template
      
                        SPListTemplate oTemplate = oWeb.ListTemplates["PictureLibrary"];

                        //Creates a new list with Title, Descrription and List Template "Picture Library" type

                        oWeb.Lists.Add(listName, description, oTemplate);
                    }
                    else
                    {
                        System.Console.WriteLine(listName + " already exists in the " + oWeb.Title + " site");
                        System.Console.ReadLine();
                    }
                }
            }
        }
    }
}

Wednesday, August 8, 2012

Add Title to Social Comments - jQuery

To insert some title or another text to social comments on a page:
You can resolve it by jQuery code:


  $(document).ready(function () {

            var socomHolders = $('div [id*="_socomHolder_"]');
            if (socomHolders.length) {

                socomHolders.each(function () {

                    var phName = $(this).attr('id');
                    var index = phName.substring(phName.lastIndexOf('socomHolder') + 
                        12, phName.length);

                    var socomContent = $('div [id*="_socomContents_' + index +'"]');
                    var newRow = $("Example : "+ index +"");
                    $(".ms-socialCommentItem", socomContent).prepend(newRow);
                });
            }
        });


Tuesday, July 31, 2012

How to know if the Page is in Edit Mode - C#

For a page we need to use:
if (Microsoft.SharePoint.SPContext.Current.FormContext.FormMode == SPControlMode.Display)
  {
   //  display mode
  }
  else // Microsoft.SharePoint.SPContext.Current.FormContext.FormMode = SPControlMode.Edit
  {
   //  edit mode
  }



and for webpart pages:

   WebPartManager mgr = this.WebPartManager;
 if (mgr.DisplayMode == WebPartManager.EditDisplayMode)
     {
        // edit mode
     }
  else
     {
  //  display mode
     }

How to know if the Page is in Edit Mode - JavaScript ?

For a page we need to use:

var pageMode = document.forms[MSOWebPartPageFormName].MSOLayout_InDesignMode.value;

if (pageMode == 1)
{
// page is in edit mode
}
else
{
// page is in browse mode
}



and for wiki pages:



var pageMode = document.forms[MSOWebPartPageFormName]._wikiPageMode.value;

if (pageMode == "Edit")
{
// page is in edit mode
}
else
{
// page is in browse mode
}



This will refer to a value of the following html input control, which is rendering on the page when it is in edit mode:






Monday, July 30, 2012

Page Layout issue - Show/Hide fields in Display/Edit Mode

If you want to hide/display fields in edit/display mode on your page layout , you can do it by adding publishingwebcontrols:editmodepanel tag.




Put your fields here


or



Put your fields here

Thursday, July 12, 2012

The same client browser session has made '6' requests in the last '11' seconds.

After the configuration of ADFS v2 to SharePoint 2010 and
when I tried to login, I found at myself that after I authenticate to ADFS, get caught up in this endless loop where go back and forth between SharePoint and ADFS.
In Fiddler it turns out that I are authenticating successfully to ADFS, I am coming back to SharePoint and it is successfully issuing the FedAuth cookie,
it redirects you to /_layouts/authenticate.aspx on the SharePoint site which clears out the FedAuth cookie and redirects me back to the ADFS site.
I basically ping pong back and forth until ADFS stops it .

In Event Viewer of ADFS Server :



I saw the exception:



Exception details:
Microsoft.IdentityServer.Web.InvalidRequestException: MSIS7042: The same client browser session has made '6' requests in the last '11' seconds. Contact your administrator for details.
at Microsoft.IdentityServer.Web.FederationPassiveAuthentication.UpdateLoopDetectionCookie()
at Microsoft.IdentityServer.Web.FederationPassiveAuthentication.SendSignInResponse(MSISSignInResponse response)



That’s because the default LogonTokenCacheExpirationWindow for the SharePoint STS is 10 minutes. In this case when I created my relying party by default it sets the token lifetime in ADFS to be 2 minutes, so as soon as it authenticated it knew the cookie was good for less time than the LogonTokenCacheExpirationWindow value. Therefore it went back to ADFS to authenticate again. And so it went, back and forth. So I needed to change the LogonTokenCacheExpirationWindow to be less than the SAML TokenLifetime.

The solution is PowerShell Script:







$sts = Get-SPSecurityTokenServiceConfig
$sts.LogonTokenCacheExpirationWindow = (New-TimeSpan –minutes 1)
$sts.Update()
iisreset

Tuesday, July 10, 2012

The workbook cannot be opened



This is error I received on any excel file, which I tried to open in browser by Office Web Apps.

The solution was granting permissions to the service account for Excel Services.
The PowerShell script, which invokes the SPWebApplication.GrantAccessToProcessIdentity method helps to solve it:



Add-PSSnapin Microsoft.SharePoint.PowerShell -EA 0

$webApp = Get-SPWebApplication "http://contoso.com"

$webApp.GrantAccessToProcessIdentity("CONTOSO\spExcelServiceApp")