protected void btnUpload_Click(object sender, EventArgs e) { FileUploadControl1.SaveAs(Server.MapPath("~/Uploads/") + FileUploadControl1.FileName); lblStatus.Text = "Successful"; lblStatus.ForeColor = System.Drawing.Color.Green; using (StreamReader st = new StreamReader(Server.MapPath("~/Uploads/") + FileUploadControl1.FileName)) { string str = st.ReadToEnd(); txbContent.Text = str; } }
protected void UploadButton_Click(object sender, EventArgs e) { if (FileUploadControl1.HasFile) { if (FileUploadControl1.PostedFile.ContentLength <= 500000) { try { string filename = Path.GetFileName(FileUploadControl1.FileName); FileUploadControl1.SaveAs(Server.MapPath("~/") + filename); StatusLabel.Text = "Upload status: File uploaded!"; } catch (Exception ex) { StatusLabel.Text = "Upload status: The file could not be uploaded. Error: " + ex.Message; } } else { StatusLabel.Text = "Upload status: Error! File size may only be 500 kb!"; } } }
//below is the button for validate Message protected void UploadButton_Click(object sender, EventArgs e) { //I make the client HL7WebService.MessageValidationV2InterfaceClient client = new HL7WebService.MessageValidationV2InterfaceClient(); //this chunk below deals with uploading the message.txt (in the markup code, I specify that this filedialog should prompt for a .TXT file) if (FileUploadControl.HasFile) { // try // { filename1 = Path.GetFileName(FileUploadControl.FileName); FileUploadControl.SaveAs(Server.MapPath("~/UploadMessage/") + filename1); // StatusLabel.Text = "Upload status: File uploaded!"; WebServiceAggregator.message1 = System.IO.File.ReadAllText(@"C:\Users\Owner\source\repos\HL7ClientProject\HL7ClientProject\UploadMessage\" + filename1); // LblValidateWithResources.Text = client.validateWithResources(text, profile, constraints, valueSetLibrary, messageId); // ValidateWithResourcesTextBox.Text = client.validateWithResources(text, profile, constraints, valueSetLibrary, messageId); // } // catch (Exception ex) // { // StatusLabel.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message; // } } //this chunk below deals with uploading the profile.xml (in the markup code, I specify that this filedialog should prompt for a .XML file) if (FileUploadControl0.HasFile) { // try // { filename2 = Path.GetFileName(FileUploadControl0.FileName); FileUploadControl0.SaveAs(Server.MapPath("~/UploadProfile/") + filename2); // StatusLabel0.Text = "Upload status: File uploaded!"; WebServiceAggregator.profile1 = System.IO.File.ReadAllText(@"C:\Users\Owner\source\repos\HL7ClientProject\HL7ClientProject\UploadProfile\" + filename2); // LblValidateWithResources.Text = client.validateWithResources(text, profile, constraints, valueSetLibrary, messageId); // ValidateWithResourcesTextBox.Text = client.validateWithResources(text, profile, constraints, valueSetLibrary, messageId); // } // catch (Exception ex) // { //Label12.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message; // } } //LblValidateWithResources.Text = client.validateWithResources(text, profile, constraints, valueSetLibrary, messageId); //this chunk below deals with uploading the constraints.xml (in the markup code, I specify that this filedialog should prompt for a .XML file) if (FileUploadControl1.HasFile) { // try // { filename3 = Path.GetFileName(FileUploadControl1.FileName); FileUploadControl1.SaveAs(Server.MapPath("~/UploadConstraints/") + filename3); //StatusLabel1.Text = "Upload status: File uploaded!"; WebServiceAggregator.constraints1 = System.IO.File.ReadAllText(@"C:\Users\Owner\source\repos\HL7ClientProject\HL7ClientProject\UploadConstraints\" + filename3); // LblValidateWithResources.Text = client.validateWithResources(text, profile, constraints, valueSetLibrary, messageId); // ValidateWithResourcesTextBox.Text = client.validateWithResources(text, profile, constraints, valueSetLibrary, messageId); // } // catch (Exception ex) // { // StatusLabel1.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message; // } } //this chunk below deals with uploading the valuesetlibrary.xml (in the markup code, I specify that this filedialog should prompt for a .XML file) if (FileUploadControl2.HasFile) { // try // { filename4 = Path.GetFileName(FileUploadControl2.FileName); FileUploadControl2.SaveAs(Server.MapPath("~/UploadValueSetLibrary/") + filename4); // StatusLabel2.Text = "Upload status: File uploaded!"; WebServiceAggregator.valueSetLibrary1 = System.IO.File.ReadAllText(@"C:\Users\Owner\source\repos\HL7ClientProject\HL7ClientProject\UploadValueSetLibrary\" + filename4); // LblValidateWithResources.Text = client.validateWithResources(text, profile, constraints, valueSetLibrary, messageId); // ValidateWithResourcesTextBox.Text = client.validateWithResources(message1, profile, constraints, valueSetLibrary, messageId); // ValidateWithResourcesTextBox.Text = client.validateWithResources(WebServiceAggregator.message1, WebServiceAggregator.profile1, WebServiceAggregator.constraints1, WebServiceAggregator.valueSetLibrary1, WebServiceAggregator.messageId1); //// } // catch (Exception ex) // { // StatusLabel2.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message; // } } //This code below checks for the correct extension in the filename. If the filename is still empty as we declared at top, it is missing. if (!(filename2.Contains(".xml")) || filename2 == "") { Response.Write("<script>alert('ERROR: Your Profile input does not exist or uses the incorrect extention, should be .XML. Please try again.')</script>"); } if (!(filename3.Contains(".xml")) || filename3 == "") { Response.Write("<script>alert('ERROR: Your Constraints input does not exist or uses the incorrect extention, should be .XML. Please try again.')</script>"); } if (!(filename4.Contains(".xml")) || filename4 == "") { Response.Write("<script>alert('ERROR: Your Value Set Library input does not exist or uses the incorrect extention, should be .XML. Please try again.')</script>"); } if ((!(filename1.Contains(".txt")) || filename1 == "")) { Response.Write("<script>alert('ERROR: Your Message input does not exist or uses the incorrect extention, should be .TXT. Please try again.')</script>"); } //if all required items have been uploaded if (FileUploadControl.HasFile && FileUploadControl0.HasFile && FileUploadControl1.HasFile && FileUploadControl2.HasFile) { try { //these lines below grab the message ID value from the profile for the Validate With Resources method WebServiceAggregator.messageId1 = XDocument.Load(@"C:\Users\Owner\source\repos\HL7ClientProject\HL7ClientProject\UploadProfile\" + filename2).Root .Descendants("Message") .Select(element => element.Attribute("ID").Value).FirstOrDefault(); //then display the report generated from validateWithResources in the text box. Notice we use message ID at the end which we grabbed in our profile upload code above ValidateWithResourcesTextBox.Text = client.validateWithResources(WebServiceAggregator.message1, WebServiceAggregator.profile1, WebServiceAggregator.constraints1, WebServiceAggregator.valueSetLibrary1, WebServiceAggregator.messageId1); // ValidateWithResourcesTextBox.Text = client.validateWithResources(WebServiceAggregator.message1, WebServiceAggregator.profile1, WebServiceAggregator.constraints1, WebServiceAggregator.valueSetLibrary1, messageId); //This code below is what grabs the counts from the json and displays them var myJsonString = client.validateWithResources(WebServiceAggregator.message1, WebServiceAggregator.profile1, WebServiceAggregator.constraints1, WebServiceAggregator.valueSetLibrary1, WebServiceAggregator.messageId1); var jo = JObject.Parse(myJsonString); var errors = jo["metaData"]["counts"]["error"].ToString(); var warnings = jo["metaData"]["counts"]["warning"].ToString(); var affirmatives = jo["metaData"]["counts"]["affirmative"].ToString(); Label11.Text = "Report Counts: " + "Errors - " + errors + " | Warnings - " + warnings + " | Affirmatives - " + affirmatives; } catch (Exception) { Response.Write("<script>alert('ERROR: One or more of your files has the incorrect content. Please try again.')</script>"); } } //otherwise display this error pop up message else { Response.Write("<script>alert('ERROR: You have not uploaded all files to generate a report. Please try again.')</script>"); } }