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);
}
}