Thursday 25 June 2015

Nintex Form Reduce width of DateTime control

********************************
To reduce the width of DateTime control, go to Nintex Form Settings >> Custom CSS and add below 
.cu-date
{
width: 120px !important;
}

.cu-date input
{
width: 70px;
}

and add cu-date class to Date\Time control 

********************************

Nintex Forms show loading dialogue for required time

One of our Nintex Form has complex Javascript which queries web services and loads meta data. For this operation, the javascript runs for few seconds and we want user not
  1.  To start typing on any field of form or accessing the form before it loads all meta data
  2.  To complain that form is incomplete before it loads all meta data
For this we can add below Javascript to show loading animation to user so that user can wait without complaining. It gives better usability.

$(window).load(function () {

waitDialog = SP.UI.ModalDialog.showWaitScreenWithNoClose('   ', 'Please wait...', 110, 280);
   
setTimeout(function () {  
waitDialog.close();
    }, 5000);
});

JQuery has to be referenced in Nintex Form. It uses SharePoint's native modal dialog.

Nintex form is blank in browser

If Nintex form is not getting rendered, that is if browse shows white page instead of Nintex form, check for any javascript error using browser debugger.

Get Current Users Display name in ASP.Net Web application

To Get current user's display name without LDAP settings.


  public string HelloUser()
        {
            string dispName = "";
            Thread.GetDomain().SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
           
            using (System.Web.Hosting.HostingEnvironment.Impersonate())
            {
                WindowsPrincipal principal = (WindowsPrincipal)User;
                PrincipalContext pc = new PrincipalContext(ContextType.Domain); ;
                UserPrincipal up = UserPrincipal.FindByIdentity(pc, principal.Identity.Name);
                dispName = up.DisplayName;
                
            }            
            return "Hello - " + dispName + ", your login is " + HttpContext.Current.User.Identity.Name;
        }

Note: Make sure windows impersonation is turned on in IIS.

Saturday 20 June 2015

SharePoint 2010 Visual WebPart gives 403 error to users

We have a Visual Webpart deployed to SharePoint 2010 with following key functionality
  1. Access SQL DB
  2. Access SP Groups to see if current user is part of few SP groups
This Web Part uses AJAX control toolkit.
Our SharePoint farms are scheduled to recycle App Pools over night.

Problem:
In the morning when a normal user access the page containing Visual Web Part, IE will show 403 error.
Once Site admin access the page the error will go away and normal users can access the page without any problem.

Solution:
·         Give Read permission for Everyone to \bin and \_app_bin folders
·         Copy AJAX Control toolkit dll to GAC
·         Add Authenticated users to group WSS_WPG

Friday 19 June 2015

Prevent users from accessing All Items page of SharePoint 2010

In our SharePoint portal we show users only Nintex Forms (can be accessed by links in emails sent by Workflows) and few web part pages restricting access to default SharePoint pages like AllItems.aspx.

To achieve this 
1. Upload 
             jquery-1.8.3.min.js   and
             jquery.SPServices-0.7.2.min.js

to Site Assets library

2. Edit AllItems.aspx page (or any page you want to restrict access to normal users) and add below script. (Even if the user try to access the page with link, they will be redirected to home page).

<script type="text/javascript" src="/SiteAssets/jquery-1.8.3.min.js"></script>
<script type="text/javascript" src="/SiteAssets/jquery.SPServices-0.7.2.min.js"></script>
<script type="text/javascript">
  $(document).ready(function() {$().SPServices({
      operation: "GetGroupCollectionFromUser",
      userLoginName: $().SPServices.SPGetCurrentUser(),
      async: false,
      completefunc: function(xData, Status) {
        if($(xData.responseXML).find("Group[Name='SiteAdmins']").length != 1) {
                                location.href = $().SPServices.SPGetCurrentSite();
                                 }
                      }
       });
});
</script>

After adding above script, only members of SiteAdmins can access that page, all other user will be redirected to home page.

Show 'Site Actions' ribbon menu only for SP Group members in SharePoint 2010

Step 1:
Create a SharePoint group 'SiteAdmins' at Site Collection level with Design and Contribute access

Step 2:
Add\Upload below 2 JS files to SiteAssets of root site
  1. jquery.SPServices-0.7.2.min.js
  2. jquery-1.8.3.min.js
Step 3: 
Refer above 2 JS in Master file.
Edit default Master page, find ‘<asp:ScriptManager’ under Form tag and replace(or include the script references) to include JQuery and SPServices scripts

 <asp:ScriptManager id="ScriptManager" runat="server" EnablePageMethods="false" EnablePartialRendering="true" EnableScriptGlobalization="false" EnableScriptLocalization="true" >
  <Scripts>                             
                                <asp:ScriptReference Path="<%$SPUrl:~SiteCollection/SiteAssets/jquery-1.8.3.min.js%>"></asp:ScriptReference>                         
                                <asp:ScriptReference Path="<%$SPUrl:~SiteCollection/SiteAssets/jquery.SPServices-0.7.2.min.js%>"></asp:ScriptReference>                               
                </Scripts>             
</asp:ScriptManager>

Step 4:
Hide ‘Site Actions’ and top ribbon for all users by default.
<!--<div id="s4-ribbonrow" class="s4-pr s4-ribbonrowhidetitle">-->
<div id="s4-ribbonrow" style="display: none;">

Step 5:
Include below script block before between </Body> and </HTML> to check if current user is member of 'SiteAdmins' group and display if yes.

<script type="text/javascript">
$(document).ready(function() {$().SPServices({
      operation: "GetGroupCollectionFromUser",
      userLoginName: $().SPServices.SPGetCurrentUser(),
      async: false,
      completefunc: function(xData, Status) {
        if($(xData.responseXML).find("Group[Name='SiteAdmins']").length == 1) {
$('#s4-ribbonrow').show();
}
      }
   });  
   });
</script>

Step 6 (Optional): If you want to display 'Welcome <current user>',  add wssuc:Welcome control (copy & paste) to some other location other than ribbon. 

Thats all, the Ribbon will be hidden for all users except for 'SiteAdmins' members. They have access to 'Site Actions' menu.