Thursday, May 1, 2014

Update Search Watermark SharePoint 2013

Assumption
- Publishing Site
- Update Watermark to Search Google
- Search control is on the page with same selector as below. If not, update it with appropriate selector and verify via rule selector of FF or equivalent.

var theSearchBox = $('div#SearchBox .ms-srch-sb input');
    var defaultSearchText = "Search this site";
    var preferredSearchText = "Search Google";
    theSearchBox.val(preferredSearchText);

    theSearchBox.focus(function () {
        if ($(this).val().indexOf(preferredSearchText) === 0) {
            $(this).val('');
        }
    });

    theSearchBox.blur(function () {
        if ($(this).val().indexOf(defaultSearchText) > -1)
            $(this).val(preferredSearchText);
    });



Wednesday, April 23, 2014

Add SP.UI.Dialog box to SharePoint hosted App Part

As per most of the links online, this is something not easily possible. However, I was able to get it to work!! I thought of sharing my newly acquired knowledge for the benefit of community.

Assumptions:
The only big assumption here is that you need code in the hosted page in order for this to work. You could easily add the little code required for this to work in any .JS file associated with the page/site.

Technologies Involved

  • Windows.postmessage/Listeners
  • SP.UI.Dialog
  • Sharepoint hosted App with 2 App Parts
Scenario/Issue
App part is added to the host page and has some link. The link on the app part should open as a dialog box. Outcome: App part page opens a SP.UI.Dialog box

My scenario
The App part 1 is linked to a list. The second app part we need to open is to allow user to add new item to the list. 

Here is how to get this working.


  1. Using Windows.postmessage and listener a channel to communicate between the App Part 1 and host page. In the App Part 1, you can add the code to App.js file or any other file that is being used. In the host you can just put the code to listen to a message.
  2. Create an App Part 2, which would be the URL of the SP.UI.Dialog commands.
  3. Click event in the App Part, should send a message to Host page.
  4. On receiving the message, host page should use the standard code of SP.UI.Dialog to open App Part 2.
  5. The last key aspect here is that you cannot close the dialog box that is opened easily. Therefore, you would need to send a message back to host, which would trigger the code to close the dialog box.
Enclosing a screen shot...describing the 3 windows. I still have to clean the UI.


Note: You could even use Jquery Dialog box, but I had issues it inconsistent loading and setting height etc. was not working.

Friday, February 28, 2014

Custom Permissions on SharePoint List/Library View

SharePoint any version does not offer permissions at a view level. You can have item level permissions, but not view level permissions. There is no easy way or server side method available.

I had a situation where it would be nice if  I could permissions at the view level. Over a year ago, I had a similar problem, but that time I told the client there was no way to set permissions at the view.

Here is a solution to set permissions at a view level. I will take a pages library in my example. In this example, if the current user does not belong to site owners group, they would be redirected to home page.

Assumptions

  • Pages Library provisioned
Solution
  1. Create a new .JS file and add it to anywhere on the site (Hint: SiteAssets)
  2. Add code like this below
  3. Goto AllItems.aspx page/view and click edit.
  4. Add a CE to the page.
  5. Link the CE to this .JS file. (That is all required)
Note: Make sure you are using the right version of SPService and Jquery as they seem to have compatibility issues.


<script src="http://code.jquery.com/jquery-1.11.0.js" type="text/javascript"></script>
<script src="/SiteAssets/jquery.SPServices-0.7.1a.min.js" type="text/javascript"></script>
<script type="text/javascript" language="javascript">
$(document).ready(function() {
//Do this for All Documents Views. The regular user does not need to view "All Documents" view.
  $().SPServices({
           operation: "GetGroupCollectionFromUser",
           userLoginName: $().SPServices.SPGetCurrentUser(),
           async: false,
           completefunc: function (xData, Status) {
               if ($(xData.responseXML).find("Group[Name='Site Owners']").length != 1) {
location.href = location.href.replace('/Forms/AllItems.aspx', '/Default.aspx');
               }
             
           }
       });
        


});


Thursday, February 27, 2014

Issue - Unable to install farm solution via Central Admin

Error: Access denied.  Only machine administrators are allowed to create administration service job definitions of type: Microsoft.SharePoint.Administration.SPSolutionDeploymentJobDefinition, Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c.

Solution for Windows Server 2012

Click Here to Solve this issue


Ratings Control SharePoint 2013 On-Prem

Adding ratings control in SharePoint 2013 on-premise requires going via Design Manager.

Here is the process:

  • Publishing Feature should be turned active.
  • Pages library should be provisioned
  • Go to Library Settings as in the image and make changes.
  • Once Ratings have been turned on, open your custom master page/page layout via Design manager to add this code.
  • Add this code inside the Head section
<!--CS: Start Create Snippets From Custom ASP.NET Markup Snippet-->
<!--SPM:<%@ Register TagPrefix="SharePointPortalControls" Namespace="Microsoft.SharePoint.Portal.WebControls"  Assembly="Microsoft.SharePoint.Portal, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>-->
  • Add this code where you want to display the average ratings
 <--<div class="article-content" align="left" style="left:0px; width:100px">
            <!--CS: Start Create Snippets From Custom ASP.NET Markup Snippet-->
<!--SPM:<SharePointPortalControls:AverageRatingFieldControl 
   ID="PageRatingControl" 
   FieldName="AverageRating" 
   runat="server"/>-->
<!--CE: End Create Snippets From Custom ASP.NET Markup Snippet-->
           </div>-->