0

I am trying to export MS Chart that is generated in c#, I was successful in addining it to itextsharp PDF using

....
 var image = Image.GetInstance(ChartPng(list, propertyList, displayNames));
.....

The chart is saved in the buffer

 using (var chartimage = new MemoryStream())
            {
                chart.SaveImage(chartimage, ChartImageFormat.Png);
                return chartimage.GetBuffer();
            }

I was able to open it in the browser, using:

 return File(ChartPng(list, propertyList, displayNames), "image/png");

How I can make it as download rather than saving it to a particular disk, any suggestions. Thanks in advance.

hncl
  • 2,331
  • 4
  • 58
  • 123

1 Answers1

1

If you are just looking to write it directly to the Response stream, you can look at my answer here:

How to refresh asp.net charts in MVC using jQuery

Edit:

To prompt the user to download the file instead, use the FileContentResult.

http://msdn.microsoft.com/en-us/library/system.web.mvc.filecontentresult.aspx

Community
  • 1
  • 1
mgnoonan
  • 6,860
  • 5
  • 22
  • 26
  • Thanks, I tried the proposed solution; the chart open in the browser. – hncl Apr 11 '12 at 03:44
  • I misread your question, I thought that was what you wanted. I have updated my answer. – mgnoonan Apr 11 '12 at 12:49
  • Thanks, I tried to use: var image = Image.GetInstance(Chart(list, propertyList, displayNames)); return FileResult(image, "image/png");. Got this error:System.Web.Mvc.FileResult' is a 'type' but is used like a 'variable' – hncl Apr 11 '12 at 19:54
  • I believe there is an overload on File that takes a `string filename`. That should prompt for the download. See http://stackoverflow.com/questions/3206682/stream-file-using-asp-net-mvc-filecontentresult-in-a-browser-with-a-name. – mgnoonan Apr 11 '12 at 20:40