Microsoft cloud engineer - SharePoint, Office 365, Azure, DotNet, Angular, JavaScript.
Microsoft cloud engineer - SharePoint, Office 365, Azure, DotNet, Angular, JavaScript.

February 2012

PowerShell – upload CSV file to List (both Server and Client OM)

Recently I had a friend ask about how to upload a local CSV data file to a SharePoint site.  The scenario is that a daily CSV file is provided on a network share and needs to be imported to SharePoint for viewing, filtering, and sorting.  The easiest way to code this was with Server Side Object Model.  Be sure to compare the source/destination columns and make sure everything lines up OK.   The schema must match for any import to be successful.

This also can be accomplished with Client Side Object Model, it just takes a little more code.   If you don’t have access to the SharePoint server this is a great option with flexibility to host a PowerShell script anywhere (desktop, job server, etc.)

 

2-24-2012 3-32-35 PM
2-24-2012 3-31-46 PM

http://blogs.technet.com/b/heyscriptingguy/archive/2010/09/22/use-powershell-to-manage-lists-views-and-items-in-sharepoint.aspx

 

Server Side Object Model

Client Side Object Model

DataSheet – master page background color hides cell text [FIXED]

While changing the background color of a master page, I noticed a new issue with DataSheet view.   DataSheet uses an ActiveX control to render the grid control.  This control uses the <BODY> background color so attempts to set the “#s4-mainarea” <DIV> with a background color were in vain.   It works for HTML content, but just not for DataSheet.  Using light color (#FFF white in the example below) is more compatible with DataSheet view’s  gray text and gray cell border.  If you have a light <BODY> background color, it may work OK, but those those with dark backgrounds … what can we do?   There are two options:

Before and After Screenshots

Here’s a site with bad colors before the fix:

bad

Here’s the same site with smart code to give a different background-color driven by “ShowInGrid” URL:

good

Option #1 – Server Side – Master page with C# code

A brief snippet of ASP.Net code written in C# can be inserted into the master page.   The server side rendering will look for a “ShowInGrid” URL parameter. 

Pro

  • Fast
  • No client browser “blink” that JS has
  • Foundation for writing other Dot Net server side code  (“smart” master pages)

Con

  • Requires [web.config] edit

Action Steps

  1. Open site with SharePoint Designer
  2. Open Master page with Edit in Advanced Mode
  3. Add the below code just before the </HEAD> tag
  4. Open INETMGR and locate the website
  5. Open [web.config] from the IIS website folder with Notepad
  6. Add the below <PageParserPath> tag.   NOTE – be sure to update the site collection relative URL to match your environment.   Enabling this for all pages (/*) is not generally recommended unless the only people with SP Designer also are trusted developers.
  7. Repeat steps #4 – #6 on each web front end server

2-22-2012 2-01-59 PM

2-22-2012 2-03-48 PM

2-22-2012 2-06-43 PM

Option #2 – Client Side – Master page with JavaScript code

A brief snippet of ASP.Net code written in C# can be inserted into the master page.

Pro

  • Does not require any server access

Con

  • Slow
  • Client browser will “blink” when JS changes the color changes from light to dark

Action Steps

  1. Open site with SharePoint Designer
  2. Open Master page with Edit in Advanced Mode
  3. Add the below code just before the </BODY> tag

2-22-2012 2-07-47 PM

© Copyright 2016
@ SPJeff

Return to Top ▲Return to Top ▲