Wednesday, August 20, 2014

Parsing a CSV file in C#

Every so often, I seem to run into a situation in which I need to parse a CSV file in order to read data into a system that I'm working with.  Rather than re-invent the wheel by writing my own parser, I tend to leverage the existing Microsoft.VisualBasic.TextFieldParser to do the work (yes, even though I'm using C#).  Here is some sample C# code that demonstrates how this can be used:


using Microsoft.VisualBasic;
using Microsoft.VisualBasic.FileIO;

...

TextFieldParser parser = new TextFieldParser(@"pathToCSVFile");
parser.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited;
parser.SetDelimiters(",");
while (!parser.EndOfData)
{
     string[] cols = parser.ReadFields();
     foreach (string col in cols)
     {
          Do something with the info in each field...
     }
}

To make a long story short, this existing Microsoft object will make your life a heck of a lot easier since it tends to handle most scenarios that would require special coding (i.e. properly handling quotes).  

Wednesday, June 11, 2014

How to obtain the PerformancePoint Dashboard Designer for SharePoint 2013

There is a lot of documentation floating around the web concerning the use of SharePoint 2013's PerformancePoint Dashboard Designer, but I had to do quite a lot of searching before I was able to determine exactly how you obtain it in the first place.  Here are the steps:

If you don't have a Business Intelligence Center site collection located on your farm, you will first need to create one via the following steps:
  1. Open Central Administration on your SharePoint 2013 environment
  2. Select Application Management
  3. Under Site Collections, select Create site collections
  4. Choose the appropriate web application where it should be installed
  5. Enter an appropriate Title and URL for your new site collection
  6. For Select experience version, select "2013"
  7. For Select a template, click on the Enterprise tab and select Business Intelligence Center
  8. Select an appropriate Primary and Secondary Site Collection Administrator
  9. Click OK
Once your Business Intelligence Center site collection is in place, use the following steps to obtain the PerformancePoint Dashboard Designer:

  1. Log on to the Business Intelligence Center site collection via your browser
  2. In the left navigation panel, select PerformancePoint Content

  3. Click on the tab that reads "PERFORMANCEPOINT"

  4. Click on the Dashboard Designer icon

  5. Click the Run button when prompted

Once the installation is complete, the Dashboard Designer will open and you can now begin working on all those other tutorials you found.

Thursday, March 20, 2014

Obtain the URL of your root website using Javascript

If you ever need to obtain the URL to your root website via Javascript code (i.e. http://rootWebsite), I've got a couple of good methods for doing so which are presented as follows:

If you're on a SharePoint site want to use CSOM:

var clientContext = new SP.ClientContext();
var rootWebsiteUrl = clientContext.get_site.get_rootWeb();


If you're on a SharePoint site and don't want to use CSOM:

var rootWebsiteUrl = _spPageContextInfo.siteServerRelativeUrl;


If you're not on a SharePoint site or, actually, have no idea what SharePoint is:

var currentLocation = document.location.toString();
var webApplicationNameIndex = currentLocation.indexOf('/', currentLocation.indexOf('://') + 3);
var rootWebsiteUrl = currentLocation.substring(0, webApplicationNameIndex);

Friday, March 14, 2014

Centering an image horizontally using CSS

If you ever need to horizontally center an image on your web page, here is a simple way to do that via CSS:
<style>

.image_Container {
    display: block;
    margin-left:auto;
    margin-right: auto;

    /* BONUS - Add a stylish border around your image */
    border: 3px solid #FFFFFF;
    border-radius: 6px 6px 6px 6px;
    box-shadow: 0 1px 7px rgba(0, 0, 0, 0.15);
    /* For IE 8 */
    border: 1px solid #EFEFEF;
    -ms-filter: "progid:DXImageTransform.Microsoft.Shadow(Strength=4, Direction=135, Color='#CCCCCC')";

</style>
...
<img class='image_Container' src='pictureUrl' />
As a bonus, I also included some CSS that will place a "stylish" border around the image, but feel free to drop that section if you'd prefer not to have a border around it.

Tuesday, January 21, 2014

Internet Explorer 8 not displaying the "display:table" property

I recently ran into a problem in which IE 8 was not rendering a table structure that I created using <div> elements.  A simplified example of  what I'm talking about is as follows:

<div style="display:table">
    <div style="display:table-row">
        <div style="display:table-cell">Column 1</div>
        <div style="display:table-cell">Column 2</div>
        <div style="display:table-cell">Column 3</div>
    </div>
</div>

Now, IE 8 supports this capability so I have the feeling that the users reporting the issue may have had Internet Explorer running in a compatibility mode to support a lower version.  Fortunately, I was able to resolve the issue by add the following <meta> element to the <head> element of the master page that I was using:

<head id="Head1" runat="server">
    ...
    <meta http-equiv="X-UA-Compatible" content="IE=Edge">
    ...
</head>

In case you're curious, this <meta> tag, specifically "IE=Edge", tells IE to utilize the latest version of Internet Explorer available.