public static DialogResult ShowFileDialog(string fileName) { FileExistsDialog dlg = new FileExistsDialog(); dlg.lblCaption.Text = string.Format("File already exists {0}", fileName); return(dlg.ShowDialog()); }
private void btnUpload_Click(object sender, EventArgs e) { if (!sFtp1.Active) { return; } if (openFileDialog1.ShowDialog() == DialogResult.OK) { int position = 0; string fileName = Path.GetFileName(openFileDialog1.FileName); FileInfo fileInf = new FileInfo(openFileDialog1.FileName); if (sFtp1.FileExists(fileName)) { DialogResult fileExistsResult = FileExistsDialog.ShowFileDialog(fileName); if (fileExistsResult == DialogResult.Cancel) { return; } if (fileExistsResult == DialogResult.No) { position = (int)sFtp1.GetFileSize(fileName); if ((int)fileInf.Length <= position) { position = 0; } } } progressBar1.Minimum = 0; progressBar1.Maximum = (int)fileInf.Length; progressBar1.Value = position; using (FileStream source = new FileStream(openFileDialog1.FileName, FileMode.Open, FileAccess.Read)) { sFtp1.PutFile(source, fileName, position, source.Length); } FillDirList(); MessageBox.Show("Done"); } }
private void btnDownload_Click(object sender, EventArgs e) { if ((lbList.SelectedIndex > -1) && (lbList.Items[lbList.SelectedIndex].ToString() != "") && (lbList.Items[lbList.SelectedIndex].ToString()[0] != '/') && (lbList.Items[lbList.SelectedIndex].ToString() != "..")) { saveFileDialog1.FileName = lbList.Items[lbList.SelectedIndex].ToString(); if (saveFileDialog1.ShowDialog() == DialogResult.OK) { int size = (int)sFtp1.GetFileSize(lbList.Items[lbList.SelectedIndex].ToString()); int position = 0; if (File.Exists(saveFileDialog1.FileName)) { DialogResult fileExistsResult = FileExistsDialog.ShowFileDialog(saveFileDialog1.FileName); if (fileExistsResult == DialogResult.Cancel) { return; } FileInfo fileInf = new FileInfo(saveFileDialog1.FileName); if ((fileExistsResult == DialogResult.No) && (size > fileInf.Length)) { position = (int)fileInf.Length; } } progressBar1.Minimum = 0; progressBar1.Maximum = size; progressBar1.Value = position; using (FileStream dest = new FileStream(saveFileDialog1.FileName, FileMode.Create)) { sFtp1.GetFile(lbList.Items[lbList.SelectedIndex].ToString(), dest, position, size); } MessageBox.Show("Done"); } } }