Getting SharePoint ULS Log Location Without Reverting To Literals

The ULS logs are pretty great, especially when you have pre-existing, non-development dependent errors occurring that make absolutely freakin no sense. It’s pretty easy to get the path using the SPDiagnosticsService object.

[csharp]

public string ULSPath()
{
try
{
return SPDiagnosticsService.Local.LogLocation;
}
catch (SqlException sqlEx)
{
SPDiagCommonHelper.TraceException(sqlEx);
}
catch (SPException spEx)
{
SPDiagCommonHelper.TraceException(spEx);
}
return string.Empty;
}
[/csharp]

Share

Comparing SPPrincipal Objects To See If Same Member

More because I needed to recall this method that anything. Simple helper method consuming two SPPrincpal objects to compare the membership. Simple property and type testing, nothing very fancy.

[csharp]

public static bool SameMember(SPPrincipal x, SPPrincipal y)

{

if ((x is SPGroup) && (y is SPGroup))

{

var leftGroup = x as SPGroup;

var rightGroup = y as SPGroup;

return string.Equals(leftGroup.Name, rightGroup.Name, StringComparison.CurrentCultureIgnoreCase);

}

if (!(x is SPUser) || !(y is SPUser))

{

return false;

}

var leftUser = x as SPUser;

var rightUser = y as SPUser;

if ((!leftUser.IsDomainGroup || !rightUser.IsDomainGroup) && (leftUser.IsDomainGroup || rightUser.IsDomainGroup))

{

return false;

}

return string.Equals(leftUser.LoginName, rightUser.LoginName, StringComparison.CurrentCultureIgnoreCase);

}

[/csharp]

Share