Me, Family, Life
Posts tagged c#
Getting the Central Admin URL for a Farm in SharePoint
Jul 30th
I recently needed to get the Url of the CA for a SharePoint farm, after a bit of hunting in the API it was tracked down under the SPAdministrationWebApplication object.
C#
SPAdministrationWebApplication caWebApp = Microsoft.SharePoint.Administration.SPAdministrationWebApplication.Local; var url = caWebApp.Sites[0].Url;
PowerShell
$caWebApp = [Microsoft.SharePoint.Administration.SPAdministrationWebApplication]::Local $caWebApp.Sites[0].Url
When is true not true?
May 31st
When you look at true stored in the .Net framework.
While playing with Pex I found out a interesting fact that the bool is a byte in the MSIL. Which means that a bool could be euqal to anything on the byte range… Now this would require you to go out of your way and create unsafe code blocks to do this. Why you would do this… No ideas
Its marked as a no-fix which is not supprising as I would not fix it either becase as they say, if you know about this and you use it then you are on your own..
Getting a Outlook MailItem from a Ribbon Event
Feb 28th
You may find this code block handy:
///
/// Gets the mail item selected in the explorer view if one is selected or instance if that is the view active.
///
///
The instance containing the event data.
/// A Outlook.MailItem for the mail being viewed.
private Outlook.MailItem GetMailItem(RibbonControlEventArgs e)
{
// Check to see if a item is select in explorer or we are in inspector.
if (e.Control.Context is Outlook.Inspector)
{
Outlook.Inspector inspector = (Outlook.Inspector)e.Control.Context;
if (inspector.CurrentItem is Outlook.MailItem)
{
return inspector.CurrentItem as Outlook.MailItem;
}
}
if (e.Control.Context is Outlook.Explorer)
{
Outlook.Explorer explorer = (Outlook.Explorer)e.Control.Context;
Outlook.Selection selectedItems = explorer.Selection;
if (selectedItems.Count != 1)
{
return null;
}
if (selectedItems[1] is Outlook.MailItem)
{
return selectedItems[1] as Outlook.MailItem;
}
}
return null;
}
