Thursday 22 August 2013

JQuery image lightbox for SharePoint 2010

When creating large content pages with multiple images embedded (like help documentation or blogs), the content may be more readable if there are small images within the body of the page that expand out to larger, light-boxed images when clicked.  Or you may prefer to have hyperlinks on the page with a unique style (like a red hyperlink) so that users can click on it to see a pop up image. 
This blog walks through the process to meet each of these scenarios.

Note that this has been implemented in SharePoint using the standard modal dialog (SP.UI.ModalDialog.showModalDialog) that comes out of the box with SP 2010.  JQuery is still required, but SharePoint does most of the heavy lifting.

The steps taken:

Part 1: Set up the CSS and Masterpage

  1. CSS: In a .css stylesheet that is referenced in your Master Page, add the following classes:
    /* Lightbox Styles */ img.ms-rteImage-LightBox {      -ms-name: "LightBox";      width: 12px;     margin:0px !important;     cursor: pointer;  }  a.ms-rteElement-LightBox {   -ms-name: "LightBox";      text-decoration:underline;     font-weight:bold; }
  2. Reference JQuery in Master Page: Within the <head> tags of your /_catalogs/masterpage/Custom.master Master Page, add a reference to the JQuery code in appropriate location (version 1.10 + is required):

    <script type="text/javascript" src="http://sitecollection/Style Library/Scripts/jquery.js"></script>
  3. MasterPage: In the footer of the same Master Page, add the following:
  4. More CSS (optional): Finally, you may wish to fix the modal dialog on the page - meaning that wherever you were scrolled to on the page, the dialog will always be in the centre of the screen.
    To do this, update a style sheet that is called by the System Master Page (most likely "v4.master" but you can check at SiteCollection/_Layouts/ChangeSiteMasterPage.aspx).
    Add the following class:

Part 2: Applying the pop-up to content pages

Applying the pop-up using images


  1. Insert a logo image on the page.  This is the one I have used:Icon Image used for Modal Dialog popup images.
  2. Apply the “Lightbox” style from the “Image Style” drop down:
  3. Insert a link on the image to the image that you want to see in the modal dialog:

Applying the pop-up using Hyperlinks

To apply the pop-up image functionality to inline text, rather than using an icon image, do the following:

  1. Insert the text into the page, highlight and select “Insert” Link
  2. Open the page in HTML mode, add the class to the <a> tag:
    a class="ms-rteElement-LightBox"
  3. Save the page and click on the link to see the image in Modal Dialog form

The finished product

Your pages look clean and mean:
And when users click on a familiar icon (or hyperlink style), a helpful modal dialog will popup and give them a full resolution image to enrich your content:


Finally, of the snippets above can be downloaded here.

Friday 12 July 2013

itemstyle.xsl Grid View returns blank rows in IE7

This is a problem that will have diminishing significance as fewer and fewer organisations are still using IE7 as their corporate browser (thank God!).
I was looking to display the output of a SharePoint CQWP as a Grid view using a custom template in XSLT.  I was able to achieve this by following this very helpful blog:
http://paulgalvinsoldblog.wordpress.com/2007/12/09/display-content-query-web-part-results-in-a-grid-table/

This was fine for me in IE8, IE9, Firefox and Chrome.

The problem came when I browsed to the site using IE7. See image:


As can be seen, a blank set of tags was being inserted by SharePoint (<>) which was creating a line break.

How did I fix it? By using Child and Descendant selectors in CSS.

in my custom style sheet, I added the following code:
tr>td>table>tbody>tr>td>table>tbody>tr>td>div>div>ul>li>table>tbody li {
height: 1px; overflow: hidden; display: none; visibility: hidden;
}

HTH. :)

Monday 8 July 2013

People Picker Field PDFs vs. Office Documents

I was having intermittent issues with a custom alert email that I had created.  It would send most of the time, but would inexplicably not always work.
A better programmer than me would have set up exception catching that wrote to the Event Viewer but I couldn't seem to get that to work (might blog on that one later).
Alas, after much frustration I noticed that the alert emails were only firing for Office Documents (eg. Word, Excel) and not for PDFs.
This perplexed me so I opened up SharePoint Manager and browsed down to the items I was trying to render.
On comparison of the properties I was trying to render to the Alert email, I noticed that Office Documents stored People Picker user names as 15;#John Smith, while PDF documents store People Picker User names as just 15.
So my short-cut function that previously read:
       private string GetPPorLookupValue(string LongString)
        // Takes People Picker or Lookup column input in the format: 15;#John Smith
        // splits it and returns "John Smith" (to right of '#')
        {
            string[] SplitArray = LongString.Split('#');
            return SplitArray[1].ToString();
        }

Needed to be made a little bit more robust by actually referring to the User Listing in SharePoint:

        private int GetPPorLookupInteger(string LongString)
        // Takes People Picker or Lookup column input in the format: 15;#John Smith or 15
        // splits it and returns integer 15 (to left of ';', if exists)
        {
            string[] SplitArray = LongString.Split(';');
            int UserNum = Convert.ToInt32(SplitArray[0]);
            return UserNum;
        }

        private string GetUserName_ID(int UserID, SPAlertHandlerParams ahp)
        // Takes User ID as a SharePoint User ID: 12
        // returns username "John Smith"
        {
            string username = "Unknown User";
            if (!(UserID == 0))
            {
                SPWeb thisweb = new SPSite(ahp.siteUrl + ahp.webUrl).AllWebs[0];
                foreach (SPUser user in thisweb.SiteUsers)
                {
                    if (user.ID.Equals(UserID))
                    {
                        username = user.Name;
                        break;
                    }
                }
                thisweb.Dispose();
            }
            return username;
        }

string ReportUpdater = GetUserName_ID(GetPPorLookupInteger(item.Properties["ReportUpdater"].ToString()), ahp);

Monday 24 June 2013

How to see Approver Comments in Alert Notification emails

Step 1: Select “Publish a Major version” of the document:

Step 2: Optionally enter Version comments which will be visible in the Version History but not in the Alert Email:



Step 3: When you set the Approval Status to “Approved”, enter the approver comments that will be visible in the alert email that is sent out:

Step 4: When the Alert is received by the user, they will see the Approver comments in the body of the email:


Default behaviour of SharePoint Alerts

I have just spent some time system testing SP Alerts and thought I would put some notes up here:

  • The Timer job that sends the alert emails runs every 5 minutes (or as defined by administrator)
  • Alerts are security trimmed. Example:
    • If a user has access to view Minor versions (eg people with Contribute permissions), they will get alerts for all changes at the minor level
    • If a user has access to ONLY Major, Approved versions (eg. site visitors) they will only get alerts at this time
  • If a user self-subscribes to a list item, and then an Admin ALSO subscribes that user to the same list item, take note that:
    • User will receive 2 alert emails
    • Administrator/user will NOT be notified that an alert already exists for that user
  • If a user self-subscribes multiple times to the same report, they will receive multiple alert emails
  • Also, there was some confusion when 2 changes are made within a 5 minute period (between 2 Timer jobs).  See the example below for activities I undertook within 5 minutes:
  1. Published a major version (Status = Pending)
  2. Set from Pending to Approved (Status = Approved)
  3. Made a change (Status = Draft, Checked out)
  4. Published MINOR version (Status = Draft, Checked in)
  5. Published a Major version (Status = Pending)
  6. Set from Pending to Approved (Status = Approved)
The alert I received was from Step 5 (when the item was in “Pending” state).  This seems strange as one would expect the alert to send information from Step 6.

Friday 24 May 2013

SharePoint 2010 Corrupt Navigation Nodes


Symptoms:

  • Response was extremely slow
  • Only affecting a single Site Collection
  • No errors in the Event Viewer
  • Still able to browse the site structure through SharePoint Designer
  • Errors on the screen said something like:
    • Error occurred while rendering navigation requested url
    • An unexpected error occured while manipulating the navigational structure of this Web.
  •  Noticed that, when a page did load, it had dozens (hundreds?) of Navigation nodes on Current navigation and Global Navigation


Suspected Cause: 

Thought that maybe the reason this was taking so long to load a page, was that the Navigation is corrupt and it was trying to build out this enormous navigation structure.

To fix:

Open PowerShell on the server, check the size of those objects at the top level:

$siteUrl = "http://WebAppURL/sites/scname"
$spWeb = Get-SPWeb $siteUrl
$spWeb.Navigation.QuickLaunch | ft Title
$spWeb.Navigation. TopNavigationBar | ft Title

  
Then, if this looks like the problem, delete the QuickLaunch Nodes, then delete the TopNavigationBar Nodes, as required:


$siteUrl = "http://WebAppURL/sites/scname"
$spWeb = Get-SPWeb $siteUrl
    Foreach($node in ($spWeb.Navigation.QuickLaunch))
{
    write-host "The node title is "$node.Title
    $node.Delete()
}
$spWeb.Dispose()



$siteUrl = "http://WebAppURL/sites/scname"
$spWeb = Get-SPWeb $siteUrl
    Foreach($node in ($spWeb.Navigation.TopNavigationBar))
{
    write-host "The node title is "$node.Title
    $node.Delete()
}
$spWeb.Dispose()


Note that I had to run these commands several times.  It looked like it would delete 80% of them, then get an error.  If this happens, then just run it again:
PowerShell error when running the above command
Add caption

Tuesday 30 April 2013

Ways to Sign in as a Different user - SharePoint 2013


As you will have already noticed the Sign in as a different user option has been deprecated from SharePoint 2013. Dirk Van den Berghe has written about it here.

So, I have found 3 options to get around this issue:
  1. Append the following string (from /_layouts) to the SharePoint URL in your browser http://mySPSite/_layouts/closeConnection.aspx?loginasanotheruser=true
  2. Launch your browser as a different user: http://www.little.org/blog/2012/07/17/launch-your-web-browser-as-another-user 
  3. Add the menu item back in (not supported and may be overwritten in future upgrades): http://nickgrattan.wordpress.com/2012/07/23/sign-in-as-different-user-and-sharepoint-2013/

Wednesday 27 February 2013

SharePoint Web Application Creation Error

 SharePoint 2010 Web Application creation error: "There is a duplicate 'Reporting Services/Data Extensions' section defined"
I was trying to create a new Web Application on my SharePoint farm and as soon as it was created, I got the following error:

When I try to browse to the site, I see a very helpful error.


Looks like a small problem.  So I went into the Web.Config file and removed that duplicate entry.

Problem was that now I got a "Server Error 500" when I tried to access the Web App's Site Collection.

I googled, fiddled, interogated logs.  All to know avail.

Eventually, in desparation, I decided to uninstall SharePoint and try again. 

Unfortunately, this time I got the above error as soon as I created the Central Admin Database.

So what was going ON?

In my case, I found that this was an issue with the Supplemental .Config file that I had created.

I had never created one of these before but, as per Microsoft Best Practice, the SharePoint Web.Config file should not be editied directly.  Changes should be made in a custom file, stored in %CommonProgramFiles%\Microsoft Shared\web server extensions\14\CONFIG

I took a loko in this directory and what should I see but not only my Supplemental file, but a very suspicious looking file called "Webconfig.rs". 

So, I removed my own Supplemental file and it resolved the issue.

I haven't figured out the exact cause of this issue yet. I suspect that as the Web Config file is updated when a new Web App is created was getting muddled.  Most probably caused by some malformed XML in my own file. 

The good news is that the problem is fixed and I can continue my install.

Thursday 21 February 2013

Content Query Web Part - Sort by two columns

OK, this is a problem I have had to solve twice now so I am blogging it for my own reference - and for anyone else out there who might be interested.

SharePoint Content Query Web Parts only allow users to Sort By a single field.

In my case, I wanted to sort a news items listing by whether it was marked "Priority News" (a Yes/No field) and then by the Publishing Date.

There are other/smarter/more complex ways of achieving this. Indeed, to sort any more than two columns it will be necessary to look at some fancy XSLT or CAML.  But for now, this is a hack solution that a content administrator can do on their own without any more than a tiny bit of config and a single line of CSS (which I have provided :)).

In the Properties of the Content Query Web Part, select "Group By" and add your Priority News Yes/No field to it.  As you want the "Yes" values to appear first, select "Show groups in Descending Order".
Under Sort By, include the next field you would like to sort by.
Then (and here comes the trick), under Group Style, select "Whitespace".

All looking OK but you may still notice a bit of padding below each group.
As such, in your Custom CSS file, simply add the following line:

.whitespace { padding-bottom:0px !important; }


Thursday 24 January 2013

Setting up SharePoint 2013 Development Environment

Setting up SharePoint 2013 Development Environment is not the most straight-forward procedure for a complete Visual Studio novice like me.
In fact, I spent quite a few hours trying to figure out this fairly tedious procedure and as a result, I have outlined the steps below:

Pre-Requisites


  1. SharePoint (either Server or Foundation) must be installed on the Server (Win 2008 R2 SP1 or Win 2012)
  2. Visual Studio 2012 (Professional, Premium or Ultimate) must be installed on the server
  3. You, the developer, must be a Local Admin on that server
In order to develop SharePoint 2013 and Office 2013 Apps in Visual Studio, when you select 'New Project...' you should see a menu structure like the following:


And then...

In order to see all these SharePoint 2013 templates, you will need to install a couple of other programs:

  1. SharePointServer 2013 Client Components SDK
  2. Microsoft OfficeDeveloper Tools for Visual Studio 2012  (Note that this is a Web Installer, so your server will need access to the Internet in order to download the required files.  If it doesn't have access to the Web, see b) below)

  3. a) Server has internet access
    If you are lucky enough that your server has access to the web, then the Web Platform Installer 4.0 (Web PI) should work fine and allow you to download the required Office Developer Tools.

    b) Server doesn't have access to the web.

    Quite commonly servers do not have Web Access on the server, the Web PI will not be able to connect to the Internet to download the latest resources.


    I Googled this for a while and thought I found a solution by downloading and installing officetools_bundle.exe from Microsoft SharePoint Developer Tools for Visual Studio 2012 - Preview:
    This all looked OK. I could now see the coveted Office/SharePoint 2013 project templates, but a problem remained whereby when I tried to create a new project using one of these templates, I got the following error:
    "An error occurred while trying to load come required components. Please ensure that the following pre-requisite components are installed: Microsoft Web Developer Tools Microsoft Exchange Web Services"
    In this case, you will need to follow instructions similar to this blog post from Terri Donohue.

    There are a couple of unique considerations for SharePoint:
    • Once you have downloaded the WebPICMD.exe to your desktop, open the Command prompt with "Run as Administrator". Otherwise, the results of the commands will flash up on the screen too quickly to see
    • The command is case sensitive! Ensure you call the command as WebpiCmd.exe /List /ListOption:Alll or you will get: "'wpicmd.exe' is not recognized as an internal or external command, operable program or batch file."
    • Note that  I changed Terri's command from ListOption: Available to ListOption: All
    • If you want to see the /List output in Notepad, append > list.txt to the end of the command (eg. WebpiCmd.exe /List /ListOption:All > list.txt)  This helps with searching for the product you require
    • The one we are looking for is "OfficeToolsForVS2012GA Microsoft Office Developer Tools for Visual Studio 2012 - Preview 2" (Or similar, depending on when you read this)
    • C:\CAT\WebPICMD\WebpiCmd.exe /Offline /Products:OfficeToolsForVS2012GA /Path:C:\CAT\WebPICMD
    • Take note of the output at the end of output when the command is complete:
                         Offline main feed:
                           file:///C:/CAT/WebPICMD/feeds/shadow-webproductlist.xml
                             To use the new offline feed, please run the following from the command line:
                               WebPICmd.exe /Install /Products:<products you want> /XML:<Offline main feed>
                                 Done !
            • Copy the WebPICMD directory to the exact same location on your server (eg. C:/CAT)
            • On the server, the command then becomes (remember to run as Admin):
              • C:\CAT\WebPICMD\WebpiCmd.exe /Install /Products:OfficeToolsForVS2012GA /XML:C:/CAT/WebPICMD/feeds/shadow-webproductlist.xml


          • Reboot the server
          • When you open Visual Studio, right click and select "Run as Administrator" as elevated permissions may be required.

          Troubleshooting:

          If you get the following error:
          "An error occurred while trying to load some required components. Please ensure that the following pre-requisite components are installed: Microsoft Web Developer Tools Microsoft Exchange Web Services"

          This means that the Developer tools are only partially installed. You will need to uninstall Microsoft Office Developer Tools for Visual Studio 2012 by:
          • Go to Control Panel > Uninstall a program
          • Select Microsoft Office Developer Tools for Visual Studio 2012 - Preview 2 - ENU
          • Click on Change to uninstall it. The setup program should launch.
          • Click on Uninstall.
          • Also, in Add/Remove Programs, uninstall  Microsoft Web Developer Tools Microsoft and Exchange Web Services if you can see them there
          • Either Download the Office Developer Tools using this Web Platform Installer, or follow the off-line instructions above.
          • This should install the Office Developer Tools and all the prerequisites (Exchange Web Services, LightSwitch HTML Client, etc).
          • Try creating your SharePoint 2013 Empty Project again.

          Tuesday 22 January 2013


          Developing SharePoint 2013 Napa Apps in Office 365 to use on your local SharePoint environment

          Napa has only been around a few months and already there is some great stuff on the net to get you started developing apps for Office 365.
          As such, this post is not really adding a lot of new content, it is just conveniently bringing some existing web content together in a step-by-step format.


          1.       Overview is here: http://msdn.microsoft.com/en-us/library/fp161179.aspx  (How to: Set up an environment for developing apps for SharePoint on Office 365)

          2.       Follow the steps here: http://msdn.microsoft.com/en-us/library/fp179924.aspx (Sign up for an Office 365 Developer Site)

          3.       Start playing with Napa and learn how to use it!

          a.       Run the project to see if it is what you want

          b.      Publish the project

          c.       Then, deploy it

          4.       Create a basic app: http://msdn.microsoft.com/en-us/library/office/apps/jj220041(v=office.15)  (How to: Create a basic app for SharePoint by using Office 365 Development Tools Preview)

          5.       Try some more complex examples here:





          6.       Option A: You have Visual Studio installed on your desktop:

          a.       You can open the project in Visual Studio now. This will automatically prompt you to install the Visual Studio Development tools for Office and SharePoint 2013 (http://msdn.microsoft.com/en-us/office/apps/fp123627.aspx)

          b.      Then you can edit this. Load it up to your own on-premise environment. Icons are 96*96px. The blue colour is: RGB(0, 114,198).

          7.       Option B: You do not have VS installed

          a.       After publishing the App, go to the publish location (https://your365site.sharepoint.com/Lists/AppPackages/Forms/AllItems.aspx)

          b.      Download the file to your desk top

          8.       Ensure that there is an App Catalog created in CA. If not, create one: http://msdn.microsoft.com/en-us/library/fp123530.aspx

          9.       Enable the apps, otherwise you will get: “Sorry, apps are turned off. If you know who runs the server, tell them to enable apps.” http://sharepointchick.com/archive/2012/07/29/setting-up-your-app-domain-for-sharepoint-2013.aspx

          10.   Install the app in your previously created App Catalog site collection (/sites/app)

          a.       Manually (Central Admin): http://msdn.microsoft.com/en-us/library/fp123517.aspx


          11.   Now when users select “Add an App” from SharePoint, you will see a Your Apps > From your Organization


          Further Reading:

          HTH :)