protected void btnUpload_Click(object sender, EventArgs e) { clsAssyBOM aB = null; try { string fn = System.IO.Path.GetFileName(filFileUpload.PostedFile.FileName); if (filFileUpload.PostedFile != null && filFileUpload.PostedFile.ContentLength > 0) { clsFileUtil f = new clsFileUtil(""); f.MakeDirectory(Server.MapPath(AAAK.TEMPDATA) + "\\"); string fullServerFileName = Server.MapPath(AAAK.TEMPDATA) + "\\" + fn; //Create the directory filFileUpload.PostedFile.SaveAs(fullServerFileName); string pName = txtProduct.Text; string pRev = txtProductRev.Text; string bRev = txtBOMRev.Text; //create an AssyBOM object try { aB = new clsAssyBOM(pName, "", pRev, 1, 1, int.Parse(bRev), "", fullServerFileName); } catch (Exception ex2) { divMsg.Controls.Add(new LiteralControl("<p>Could not upload the BOM because of the following errors:</p>" + aB.HTML_ErrorMsg)); return; } if (aB == null) { divMsg.Controls.Add(new LiteralControl("<p>Could not upload the BOM. Please make sure you provided a valid upload BOM.</p>" + "Assembly BOM Object was null")); return; } else if (aB.HTML_ErrorMsg != "") { divMsg.Controls.Add(new LiteralControl("<p>Could not upload the BOM. Please make sure you provided a valid upload BOM.</p>" + "The error encountered was: " + aB.HTML_ErrorMsg)); return; } //Continue with upload if no errors happened during initialization if (aB.UploadToDB()) { divMsg.Controls.Add(new LiteralControl("<p>BOM Successfully Uploaded! Next step is redirect so user can view uploaded BOM.</p>")); } else { string errorResult = aB.HTML_ErrorMsg; string partAnalysisResult = aB.HTML_BadPartMessage; if (partAnalysisResult != "") { divMsg.Controls.Add(new LiteralControl("<p>Could not upload the BOM because of the following part number errors:</p>" + partAnalysisResult)); } if (errorResult != "") { divMsg.Controls.Add(new LiteralControl("<p>Could not upload the BOM because of the following errors:</p>" + errorResult)); } if (errorResult != "" || partAnalysisResult != "") { divResult.Controls.Clear(); return; } } } else { divMsg.Controls.Add(new LiteralControl("<p>" + fn + " is not a legal Upload BOM. Please make sure you have selected a valid file.")); } } catch (Exception ex) { string errMsg = ex.GetType().ToString() + ex.Message + ex.StackTrace; divMsg.Controls.Add(new LiteralControl("<p>" + errMsg.Replace(AAAK.vbCRLF, DynControls.html_linebreak_string()) + "</p>")); } }
protected void btnUpload_Click(object sender, EventArgs e) { //HttpResponse resp = HttpContext.Current.Response; //Response.AddHeader("Content-Type", "text/event-stream"); //Response.AddHeader("Cache-Control", "no-cache"); //Response.AddHeader("Access-Control-Allow-Origin", "*"); //Response.AddHeader("Connection", "keep-alive"); clsFileUtil f = new clsFileUtil(""); string fullServerFileName = ""; SSERelay resp = new SSERelay(Response); List <string> lstFileNames = new List <string>(); try { string fn = System.IO.Path.GetFileName(filFileUpload.PostedFile.FileName); string fd = Server.MapPath(AAAK.TEMPDATA) + "\\"; fullServerFileName = fd + "\\" + fn; if (filFileUpload.PostedFile != null && filFileUpload.PostedFile.ContentLength > 0) { f.MakeDirectory(fd + "\\"); //Save the uploaded file filFileUpload.PostedFile.SaveAs(fullServerFileName); //****If zip file, unzip and start loop here****// if (fn.EndsWith(".zip")) { } else { lstFileNames.Add(fn); } clsOTSUploader cOU = new clsOTSUploader(); for (int i = 0; i < lstFileNames.Count(); i++) { if (rdbOTSImport.Checked) { string processResult = cOU.ProcessFile(resp, fd, fn); } else { string processResult = cOU.ProcessFileForInventory(resp, fd, fn, 1, txtInvComment.Text.ToUpper()); } } } else { resp.send(fn + " is not a legal File. Please make sure you have selected a valid file."); resp.send("File not processed."); } //Put the stringbuilder in divMsg divResult.InnerHtml = resp.GetMessageBlock(); } catch (Exception ex) { string errMsg = ex.GetType().ToString() + ex.Message + ex.StackTrace; resp.send("data: " + errMsg.Replace(AAAK.vbCRLF, DynControls.html_linebreak_string())); //divMsg.Controls.Add(new LiteralControl("<p>" + errMsg.Replace(AAAK.vbCRLF, DynControls.html_linebreak_string()) + "</p>")); } finally { try { System.IO.FileInfo fl = new System.IO.FileInfo(fullServerFileName); fl.Delete(); } catch (Exception eM) { string errM = eM.Message + eM.StackTrace; } } }