Created
April 17, 2015 18:51
-
-
Save mskutta/c9336e8ab4a347452ca2 to your computer and use it in GitHub Desktop.
How to parse a CSV file contained in a Sitecore MediaItem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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