lundi 6 avril 2015

Can't save Chart Image


Vote count:

0




In my web app i'm generating a chart on the fly (with no markup since I don't want to render it, just to save the image to a servers file)


An exception of type 'System.IO.IOException' occurred in mscorlib.dll but was not handled in user code, stating that the process can't access the file since it's already being used in another process - but i'm not using it anywhere else.


My code for creating and saving the chart(s) is the following:



protected void btnClick_SaveChart(object sender, EventArgs e)
{
Chart Chart1 = new Chart();
Chart1.ChartAreas.Add("ChartArea1");
Chart1.Width = 1000;
Chart1.Height = 450;

SqlConnection cn = new SqlConnection(AppConfig.ConnectionString);
SqlDataAdapter ad = new SqlDataAdapter("dbo.[spSales]", cn);
ad.SelectCommand.CommandType = CommandType.StoredProcedure;

DataSet ch = new DataSet();
ad.Fill(ch);
Chart1.DataSource = ch.Tables[0];

Chart1.Series.Add("Sales");
Chart1.Series["Sales"].ChartType = SeriesChartType.Line;
Chart1.ChartAreas[0].AxisX.LabelStyle.Angle = -90;
Chart1.Series["Sales"].YValueMembers = "Total";
Chart1.Series["Sales"].XValueMember = "sales";
Chart1.ChartAreas[0].AxisX.LabelStyle.Format = "{dd-MM}";
Chart1.Legends.Add(new Legend("Legend1"));
Chart1.Series["Sales"].Legend = "Legend1";
Chart1.Series["Sales"].IsVisibleInLegend = true;

Chart1.SaveImage("C:\\Users\\James\\Documents\\Chart1.png", ChartImageFormat.Png);
}


What could be the problem here? Is it browser specific?



asked 40 secs ago







Can't save Chart Image

Aucun commentaire:

Enregistrer un commentaire