Silverlight charts are downloaded to an Excel file

Source: Internet
Author: User
Tags silverlight

One, Silverlight Xaml.cs File button Trigger method

1.//Download Chart
private void Btndown_click (object sender, RoutedEventArgs e)
{
Dbserviceclient svc = new Dbserviceclient ();
Svc. Generateexcelreportasync ();
Svc. generateexcelreportcompleted + = new Eventhandler<generateexcelreportcompletedeventargs> (svc_ generateexcelreportcompleted);
}

2.//delegate to pop up the download prompt box locally and delete the Excel file on the server

private void Svc_generateexcelreportcompleted (object sender, Generateexcelreportcompletedeventargs e)
{
string strexcelname = E.result;
String Struri = Application.Current.Host.Source.AbsoluteUri.Substring (0, Application.Current.Host.Source.AbsoluteUri.IndexOf ("/clientbin")) + "/temp/" + strexcelname;
Struri = "window.location.href=" + Struri + "';";
System.Windows.Browser.HtmlPage.Window.Eval (Struri);//local pop-up download prompt box
Delete Excel temp file
Dbserviceclient svc = new Dbserviceclient ();
Svc. Deleteexcelreportasync ();
}

Second, WCF

1.//Download Chart
[OperationContract]
[Serviceknowntype (typeof (ListItem))]
public string Generateexcelreport ()
{
String Strtemplatepath = "reportmgt\\template\\silverlightchart\\" + strappcode;
String Strexcelvisualpath = String. Format ("/{0}/{1}.xls", Strtemplatepath, strchartexcelname);//excel template Address
Strexcelvisualpath = Context.Request.ApplicationPath + Strexcelvisualpath;
DataSet ds = new DataSet ();
ds = Dtchart.dataset;
String strexcelchartpath = new Createexcelchart (). Create (Strexcelvisualpath, DS, Strtitlechart, "", "");//Download the report to the specified address (under the Temp folder)

Strexcelname = string. Format ("{0}.xls", strtitlechart);
return strexcelname;
}

2,//delete the chart on the server
[OperationContract]
[Serviceknowntype (typeof (ListItem))]
public void Deleteexcelreport ()
{
Check if directory exists (translates to physical address based on virtual address)
String path = Context.Server.MapPath (Context.Request.ApplicationPath) + "\\Temp\\" + strexcelname;
File.exists ("D:\\iirs2010new\\sln\\bs. Eap. Portal\\temp/xxxxxx yield change chart. xls ")
if (file.exists (path))
{
File.delete (path);
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.