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);