Wednesday, December 17, 2008

Changing a chart to store the image on disk

If you want the Microsoft Chart Control to use real semi-persistent URLs for images rather than using charting.axd then:

1. change the web.config settings to include

[add key="ChartImageHandler" value="storage=file;timeout=20;dir=e:\inetpub\yourapp\temp\;deleteAfterServicing=false"/]

2. add this code to your chart initialisation

Chart1.ImageStorageMode = ImageStorageMode.UseImageLocation;
Chart1.ImageLocation = Request.ApplicationPath + "/temp/ChartPic_#SEQ(300,3)";

That seems to work for me :)

One word of warning though: This does open up a security hole - it means charts can be requested multiple times and URLs can be guessed!

No comments:

Post a Comment