Skip to content

Instantly share code, notes, and snippets.

@mskutta
Created April 17, 2015 18:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mskutta/c9336e8ab4a347452ca2 to your computer and use it in GitHub Desktop.
Save mskutta/c9336e8ab4a347452ca2 to your computer and use it in GitHub Desktop.
How to parse a CSV file contained in a Sitecore MediaItem
public static List<Price> ReadPrices(MediaItem mediaItem)
{
var prices = new List<Price>();
using (var stream = mediaItem.GetMediaStream())
{
using (TextReader reader = new StreamReader(stream))
{
var csv = new CsvReader(reader);
while (csv.Read())
{
var price = new Price();
price.Product = csv.GetField<string>("Product");
price.PerLb = csv.GetField<string>("per lb");
price.Per3Lb = csv.GetField<string>("3+ lb");
price.Per5Lb = csv.GetField<string>("5+ lb");
price.Per8Lb = csv.GetField<string>("8+ lb");
prices.Add(price);
}
return prices;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment