hi...
I have developed webpart with one MsChart in it and one DropDownList With 2 different types of Export options(PDF,WORD).wHEN FIRST TIME I SELECTED pdf option it exports correctly but after i selects another option Like Word it doesnt shows any result ,i think it has to refresh the page after first Pdf export succussfully.So cant understood how to Refresh in below Code ....so plz any one Help me with code also...
My code as follows....
public partial class VisualWebPart1UserControl : UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
// Create new data series and set it's visual attributes
Series series = new Series("Spline");
series.ChartType = SeriesChartType.Spline;
series.BorderWidth = 3;
series.ShadowOffset = 2;
// Populate new series with data
series.Points.AddY(67);
series.Points.AddY(57);
series.Points.AddY(83);
series.Points.AddY(23);
series.Points.AddY(70);
series.Points.AddY(60);
series.Points.AddY(90);
series.Points.AddY(20);
// Add series into the chart's series collection
Chart1.Series.Add(series);
// Page.Response.Redirect(HttpContext.Current.Request.Url.ToString(), true);
}
}
protected void ddl_chanched(object sender, EventArgs e)
{
if (DropDownList1.SelectedValue == "Pdf")
{
Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
using (MemoryStream stream = new MemoryStream())
{
Chart1.SaveImage(stream, ChartImageFormat.Png);
iTextSharp.text.Image chartImage = iTextSharp.text.Image.GetInstance(stream.GetBuffer());
string lbl1 = Label1.Text.ToString();
pdfDoc.Add(new Paragraph(lbl1));
chartImage.ScalePercent(75f);
pdfDoc.Add(chartImage);
pdfDoc.Close();
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=Chart.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Write(pdfDoc);
Response.End();
//ScriptManager.RegisterStartupScript(this, GetType(),
// "name", "reloadPage();", true);
//ScriptManager.RegisterStartupScript(this, GetType(), Guid.NewGuid().ToString(), script, true);
// ScriptManager.RegisterStartupScript(this, GetType(),
// "ServerControlScript", script, true);
}
}
else if (DropDownList1.SelectedValue == "Word")
{
//string str = "<script>alert(\"ok\");</script>";
// Page.ClientScript.RegisterStartupScript(this.GetType(), "Script", str, false);
// ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "MyFun1", "reloadPage();", true);
string tmpChartName = "test2.jpg";
string imgPath = HttpContext.Current.Request.PhysicalApplicationPath + tmpChartName;
Chart1.SaveImage(imgPath);
string imgPath2 = Request.Url.GetLeftPart(UriPartial.Authority) + VirtualPathUtility.ToAbsolute("~/" + tmpChartName);
Response.Clear();
Response.ContentType = "application/vnd.ms-word";
Response.AddHeader("Content-Disposition", "attachment; filename=test.doc;");
StringWriter stringWrite = new StringWriter();
HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
string headerTable = @"
<img src='" + imgPath2 + @"' \> |
";
Response.Write(headerTable);
Response.Write(stringWrite.ToString());
Response.End();
}
}