2
我有一個頁面根據選定的選項顯示生成的MS圖表。C#-MS圖表圖像在保存後變爲空白
以前,當我在我的本地,我可以保存圖表圖像,並通過ExcelDl_Click將其顯示在Excel表格中。但在將系統部署到IIS後,我得到的已保存的「圖表」圖像是空白的方形圖像。
這是這是對本地和部署使用的代碼:
protected void ExcelDl_Click(object sender, EventArgs e)
{
Response.Clear();
Response.Buffer = true;
Response.AddHeader("content-disposition", "attachment;filename=ViewHistoryChart.xls");
Response.ContentType = "application/vnd.ms-excel";
Response.Charset = "";
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
Chart1.RenderControl(hw);
string tmpChartName = "ChartImage.jpg";
string imgPath = HttpContext.Current.Request.PhysicalApplicationPath + tmpChartName;
Chart1.SaveImage(imgPath);
string src = tmpChartName;
string img = string.Format("<img src = '{0}{1}' />", HttpContext.Current.Request.PhysicalApplicationPath, src);
Table table = new Table();
TableRow row = new TableRow();
Unit width = new Unit(500, UnitType.Pixel);
row.Cells.Add(new TableCell());
row.Cells[0].Width = width;
row.Cells[0].Controls.Add(new Label { Text = ChartTitle.Text, ForeColor=Color.Red, });
table.Rows.Add(row);
row = new TableRow();
row.Cells.Add(new TableCell());
row.Cells[0].Controls.Add(new Literal { Text = lblSectionFunctionSelected.Text });
table.Rows.Add(row);
row = new TableRow();
row.Cells.Add(new TableCell());
row.Cells[0].Controls.Add(new Literal { Text = img });
table.Rows.Add(row);
row.Cells.Add(new TableCell());
row.Cells[0].Controls.Add(new Literal { Text = lbllegendHistory.Text });
table.Rows.Add(row);
sw = new StringWriter();
hw = new HtmlTextWriter(sw);
table.RenderControl(hw);
Response.Write(sw.ToString());
Response.Flush();
Response.End();
}
當我點擊頁面上的ChartImg.axd圖像鏈接上,正確地顯示在圖表。但是當我點擊ExcelDl_Click後,該鏈接重新打開後將不顯示任何內容。我有一種感覺,它與我如何保存圖像有關,但我不確定。是否有任何軟件包更新需要解決這個問題?任何幫助將不勝感激。
好吧,我試過這樣做,它仍然保存爲相同的白色方形圖像。我甚至試圖完全訪問AppPool。你的回答似乎表明有另一種選擇?我還可以做些什麼? – mhfour