private void btnZip_Click(object sender, EventArgs e) { // make sure there are files to zip if (lstFilePaths.Items.Count < 1) { MessageBox.Show("There are no files queued for the zip operation", "Empty File Set"); return; } // make sure there is a destination defined if (saveFolder.Text == string.Empty && workingDir == string.Empty) { saveFolder.Text = frm1.createGDXTempFolder(); } else // change temp zip path { saveFolder.Text = frm1.createGDXTempFolder(); } saveFolder.Refresh(); // name the zip file whatever the folder is named // by splitting the file path to get the folder name string[] sTemp = saveFolder.Text.Split('\\'); sZipFileName = sTemp[sTemp.Length - 1].ToString(); // check to see if zipped file already exists // user may rename it in the text box if it does. FileInfo fi = new FileInfo(saveFolder.Text + "\\" + sZipFileName + ".zip"); if (fi.Exists) { // move it to the folder try { MessageBox.Show("The file " + sZipFileName + ".zip already exists in " + saveFolder.Text + "\\. \n" + "Choose another folder to save the file. (Options Menu)"); //frm1.sbLabel.Text = "Choose another Folder to save the file. (Options Menu)"; //machen return; } catch { MessageBox.Show("Rename the file or select a new location."); return; } } // Check for the existence of the target folder and // create it if it does not exist if (!System.IO.Directory.Exists(saveFolder.Text + "\\TempZipFile\\")) { System.IO.Directory.CreateDirectory(saveFolder.Text + "\\TempZipFile\\"); } // Set up a string to hold the path to the temp folder string sTargetFolderPath = (saveFolder.Text + "\\TempZipFile\\"); // Process the files and move each into the target folder for (int i = 0; i < lstFilePaths.Items.Count; i++) { string filePath = lstFilePaths.Items[i].ToString(); FileInfo fi2 = new FileInfo(filePath); if (fi2.Exists) { // move it to the folder try { fi2.CopyTo(sTargetFolderPath + fi2.Name, true); } catch { // clean up if the operation failed System.IO.Directory.Delete(sTargetFolderPath); MessageBox.Show("Could not copy files to temp folder.", "File Error"); return; } } } // zip up the files try { //frm1.sbProgressBar.Visible = true; //frm1.sbLabel.Text = "Zipping files, please wait ..."; //frm1.statusBar.Refresh(); //machen UploadWait uw = new UploadWait(); uw.Show(); uw.lblUploadWait.Text = "Zipping files..."; string[] filenames = Directory.GetFiles(sTargetFolderPath); // Zip up the files - From SharpZipLib Demo Code using (ZipOutputStream s = new ZipOutputStream(File.Create(saveFolder.Text + "\\" + sZipFileName + ".zip"))) { s.SetLevel(9); // 0-9, 9 being the highest level of compression byte[] buffer = new byte[4096]; foreach (string file in filenames) { //frm1.sbProgressBar.PerformStep(); //machen ICSharpCode.SharpZipLib.Zip.ZipEntry entry = new ICSharpCode.SharpZipLib.Zip.ZipEntry(Path.GetFileName(file)); entry.DateTime = DateTime.Now; s.PutNextEntry(entry); using (System.IO.FileStream fs = File.OpenRead(file)) { int sourceBytes; do { sourceBytes = fs.Read(buffer, 0, buffer.Length); s.Write(buffer, 0, sourceBytes); } while (sourceBytes > 0); } } s.Finish(); s.Close(); } uw.lblUploadWait.Visible = false; uw.lblUploadRes.Text = "Files have been zipped."; uw.lblUploadRes.Visible = true; uw.prbUpload.Style = ProgressBarStyle.Continuous; uw.prbUpload.Value = 100; uw.btnCancel.Visible = false; uw.btnOk.Visible = true; // remove the progress bar + change lable //sbProgressBar.Visible = false; //sbLabel.Text = "Files have been zipped. Zip file " + frm1.fpath_file + "created."; //machen // clean up files by deleting the temp folder and its content System.IO.Directory.Delete(saveFolder.Text + "\\TempZipFile\\", true); // Notify user fpath = saveFolder.Text + "\\" + sZipFileName + ".zip"; //MessageBox.Show("Zip file " + frm1.fpath_file + " created."); filePath = sZipFileName + ".zip"; //frm1.txbFilename.Refresh(); //machen //show savefolder in mainForm //frm1.saveFolder.Text = saveFolder.Text; //machen // empty everything lstFilePaths.Items.Clear(); txtAddFile.Text = string.Empty; saveFolder.Text = string.Empty; workingDir = string.Empty; //MessageBox.Show("Zipfilename: ", sZipFileName); this.DialogResult = DialogResult.OK; this.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message.ToString(), "Zip Operation Error"); //frm1.sbLabel.Text = "Zip Operation Error"; //machen } }
private void btnUpload_Click(object sender, EventArgs e) { if (fpath_file == string.Empty) { MessageBox.Show("Please select a file to upload."); return; } if(txtFName.Text == string.Empty || txtFDescription.Text == string.Empty || txtFTags.Text == string.Empty) { MessageBox.Show("Please enter filename, description and tags"); return; } if(username.Text == string.Empty || password.Text == string.Empty) { MessageBox.Show("Please enter username and password"); return; } sbProgressBar.Visible = true; sbLabel.Text = "Uploading, please wait ... "; UploadWait uw = new UploadWait(); uw.Show(); NameValueCollection fields = new NameValueCollection(); fields.Add("upload[name]", txtFName.Text); fields.Add("upload[description]", txtFDescription.Text); fields.Add("upload[tag_list]", txtFTags.Text); fields.Add("upload[contains_vector_data]", chbFRaster.CheckState.GetHashCode().ToString()); //changed with raster_data fields.Add("upload[contains_raster_data]", chbFVector.CheckState.GetHashCode().ToString()); KeyValuePair<string, string> credentials = new KeyValuePair<string, string>(username.Text, password.Text); //start upload String result = UploadClass.upload(fields, fpath_file, credentials); //display results uw.Show(); uw.lblUploadWait.Visible = false; uw.lblUploadRes.Text = result; uw.lblUploadRes.Visible = true; uw.prbUpload.Style = ProgressBarStyle.Continuous; uw.prbUpload.Value = 100; uw.btnCancel.Visible = false; uw.btnOk.Visible = true; //MessageBox.Show(result); sbProgressBar.Visible = false; sbLabel.Text = result; }