Created
December 31, 2014 01:50
-
-
Save argodev/68b8bf0fdf24bb0486b2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
[AllowAnonymous] | |
public ActionResult Export() | |
{ | |
var d1 = db.TimeSlots | |
.Where(x => x.DisplayInSchedule) | |
.OrderBy(x => x.StartTime) | |
.ThenBy(x => x.EndTime) | |
.ToList(); | |
//Response.ClearContent(); | |
var fileName = string.Format("CodeMashSchedule_{0}.csv", DateTime.Now.ToString("yyMMddHHmmss")); | |
var builder = new StringBuilder(); | |
builder.AppendFormat("\u0022{0}\u0022,\u0022{1}\u0022,\u0022{2}\u0022,\u0022{3}\u0022,\u0022{4}\u0022,\u0022{5}\u0022,\u0022{6}\u0022,\u0022{7}\u0022,\u0022{8}\u0022", | |
"SlotName", | |
"StartTime", | |
"EndTime", | |
"SessionType", | |
"Title", | |
"Speaker1", | |
"Speaker2", | |
"Room1", | |
"Room2").AppendLine(); | |
foreach (var item in d1) | |
{ | |
foreach (var session in item.Sessions) | |
{ | |
builder.AppendFormat("\u0022{0}\u0022,\u0022{1}\u0022,\u0022{2}\u0022,\u0022{3}\u0022,\u0022{4}\u0022,\u0022{5}\u0022,\u0022{6}\u0022,\u0022{7}\u0022,\u0022{8}\u0022", | |
item.Name, | |
item.StartTime, | |
item.EndTime, | |
HttpUtility.HtmlDecode(session.SessionType.Title), | |
session.Title, | |
GetSpeakerDisplayName(session.Speaker), | |
GetSpeakerDisplayName(session.SecondarySpeaker), | |
GetRoom01String(session.Rooms), | |
GetRoom02String(session.Rooms)).AppendLine(); | |
} | |
} | |
var data = Encoding.UTF8.GetBytes(builder.ToString()); | |
//var result = Encoding.UTF8.GetPreamble().Concat(data).ToArray(); | |
//return File(result, "application/csv", fileName); | |
return File(data, "application/csv", fileName); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment