public static DialogResult ShowFileDialog(string fileName)
        {
            FileExistsDialog dlg = new FileExistsDialog();

            dlg.lblCaption.Text = string.Format("File already exists {0}", fileName);
            return(dlg.ShowDialog());
        }
Exemplo n.º 2
0
        private void btnUpload_Click(object sender, System.EventArgs e)
        {
            if (!ftp1.Active)
            {
                return;
            }

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                int    position = 0;
                string fileName = Path.GetFileName(openFileDialog1.FileName);

                FileInfo fileInf = new FileInfo(openFileDialog1.FileName);

                if (ftp1.FileExists(fileName))
                {
                    DialogResult fileExistsResult = FileExistsDialog.ShowFileDialog(fileName);

                    if (fileExistsResult == DialogResult.Cancel)
                    {
                        return;
                    }

                    if (fileExistsResult == DialogResult.No)
                    {
                        position = (int)ftp1.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))
                {
                    ftp1.PutFile(source, fileName, position, -1);
                }
                MessageBox.Show("Done");

                FillDirList();
            }
        }
Exemplo n.º 3
0
        private void btnDownload_Click(object sender, System.EventArgs e)
        {
            if ((lbList.SelectedIndex > -1) &&
                (lbList.Items[lbList.SelectedIndex].ToString() != "") &&
                (lbList.Items[lbList.SelectedIndex].ToString()[0] != '/'))
            {
                saveFileDialog1.FileName = lbList.Items[lbList.SelectedIndex].ToString();
                if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    int size     = (int)ftp1.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))
                    {
                        ftp1.GetFile(lbList.Items[lbList.SelectedIndex].ToString(), dest, position, -1);
                    }
                    MessageBox.Show("Done");
                }
            }
        }