protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { StatisticsServiceSoapClient serviceclient = new StatisticsServiceSoapClient(); PopulateControls(serviceclient.GetStatistics()); } }
/// <summary> /// Uploads csv file to the server /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void UploadButton_Click(object sender, EventArgs e) { if (FileUploadControl.HasFile) { try { if (FileUploadControl.PostedFile.ContentType == "application/CSV" || FileUploadControl.PostedFile.ContentType == "application/vnd.ms-excel") { if (FileUploadControl.PostedFile.ContentLength < 102400) { string filename = Path.GetFileName(FileUploadControl.FileName); string serverPath = Server.MapPath("~/") + filename; FileUploadControl.SaveAs(serverPath); var bytes = File.ReadAllBytes(serverPath); StatisticsServiceSoapClient serviceclient = new StatisticsServiceSoapClient(); serviceclient.UploadFile(bytes, filename); lblStatus.Text = "File uploaded!"; List <StatisticsServiceRef.Statistics> lst = serviceclient.GetStatistics(); PopulateControls(lst); } else { lblStatus.Text = "The file has to be less than 100 kb!"; } } else { lblStatus.Text = "Only CSV files are accepted!"; } } catch (Exception ex) { lblStatus.Text = "The following error occured: " + ex.Message; } } }