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