public void DownloadFile(CruxDB dbObject, DataBucket sesBucket, int docClassId) { byte[] doc = dbObject.getProjectDocument(docClassId); //HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create("http://www.lotbanking.com/Downloads/" + fileName); //HttpWebResponse objResponse = (HttpWebResponse)objRequest.GetResponse(); //int bufferSize = 1; //Context.Response.Clear(); //Context.Response.ClearHeaders(); //Context.Response.ClearContent(); //Context.Response.AppendHeader("Content-Disposition:", "attachment; filename=Sample.zip"); //Context.Response.AppendHeader("Content-Length", objResponse.ContentLength.ToString()); //Context.Response.ContentType = "application/download"; //byte[] byteBuffer = new byte[bufferSize + 1]; //MemoryStream memStrm = new MemoryStream(byteBuffer, true); //Stream strm = objRequest.GetResponse().GetResponseStream(); //byte[] bytes = new byte[bufferSize + 1]; //while (strm.Read(byteBuffer, 0, byteBuffer.Length) > 0) //{ // Context.Response.BinaryWrite(memStrm.ToArray()); // Context.Response.Flush(); //} //Context.Response.Close(); //Context.Response.End(); //memStrm.Close(); //memStrm.Dispose(); //strm.Dispose(); }
/// <summary> /// Upload a file to the server. The intent is that a user will click a submit button /// on the Due Diligence page. This will bring up a list of all the documents they have /// selected for upload for them to review. If they want to upload that list then they /// click another button. That button will call this function. /// </summary> /// <param name="pathName">Current location of the file you wish to upload</param> /// <param name="fs">File stream in which the file is located for uploading. example: FileUpload1.PostedFiles.InputStream</param> /// <param name="dbObject">Used to access the database</param> /// <param name="sesBucket">Current DataBucket that is in the Session variable</param> public Label UploadFile(CruxDB dbObject, DataBucket sesBucket, HttpRequest Request, HttpContext Context, int docClassId) { Label lblFileUploadStatus = new Label(); HttpFileCollection multipleFiles = Request.Files; for (int fileCount = 0; fileCount < multipleFiles.Count; fileCount++) { string fileName = Path.GetFileName(multipleFiles[fileCount].FileName); string ext = Path.GetExtension(fileName); HttpPostedFile uploadedFile = multipleFiles[fileCount]; if (uploadedFile.ContentLength > 0) { Stream fs = uploadedFile.InputStream; BinaryReader br = new BinaryReader(fs); Byte[] bytes = br.ReadBytes((Int32)fs.Length); dbObject.insertProjectDocument(sesBucket._userID, fileName, bytes, docClassId); lblFileUploadStatus.Text += fileName + "Saved <BR>"; } } return lblFileUploadStatus; }
protected void btnSubmit_Click(object sender, EventArgs e) { CruxDB DBObject = new CruxDB(); int numberLots = 0;// = Int32.Parse(txtNumberOfLots.Text); if (txtNumberOfLots.Text == "") { } else { numberLots = Int32.Parse(txtNumberOfLots.Text); } string locationNotes = ""; decimal acquisitionPrice; decimal improvementCost; decimal.TryParse(txtAcquisitionPrice.Text, NumberStyles.Currency, NumberFormatInfo.InvariantInfo, out acquisitionPrice); decimal.TryParse(txtImprovementCosts.Text, NumberStyles.Currency, NumberFormatInfo.InvariantInfo, out improvementCost); try { if (((DataBucket)Session["UserData"])._userID > 0) { //We need to add validation here, currently a user can enter an empty project if (txtProjectName.Text == "" || txtFirstStreet.Text == "" || txtSecondStreet.Text == "" || txtCity.Text == "" || txtState.Text == "" || txtCardinal.Text == "" || txtAcquisitionPrice.Text == "" || txtImprovementCosts.Text == "") { lblDataInserted.Visible = true; lblDataInserted.ForeColor = System.Drawing.Color.Red; lblDataInserted.Text = "Please fill in all fields"; } else { DBObject.insertProject(LotBankingCrux_v_1.Crux.CruxDB.dbID, txtProjectName.Text, txtFirstStreet.Text, txtSecondStreet.Text, txtCity.Text, txtState.Text, txtCardinal.Text, locationNotes, acquisitionPrice, improvementCost, numberLots); lblDataInserted.Visible = true; lblDataInserted.ForeColor = System.Drawing.Color.Green; lblDataInserted.Text = "Data Inserted"; } } else Response.Redirect("Login.aspx"); if (dbObject.GetReqFinInfoChecked(((DataBucket)Session["UserData"])._userID) > 0) { lblAddInfoReq.Visible = true; } resetControls(); } catch (MySqlException ex) { lblDataInserted.Text = ex.Message; } //else //{ // DataInserted.ForeColor = System.Drawing.Color.Red; // DataInserted.Text = "Error!"; // DataInserted.Visible = true; //} }