Exemple #1
0
 private void uploadFolderToolStripMenuItem_Click(object sender, EventArgs e)
 {
     // upload folder
     using (FolderBrowserDialog openFolder = new FolderBrowserDialog {
         Description = "Select the folder to upload..."
     })
     {
         if (openFolder.ShowDialog() == DialogResult.OK)
         {
             Enabled = false;
             NodeFile file       = (NodeFile)treeView1.SelectedNode.Tag;
             string   folderName = GetFolderName(openFolder.SelectedPath);
             if (file.IsDirectory)
             {
                 UploadFolder(openFolder.SelectedPath, SelectedFilePath.Replace("\\", "/").Trim() + folderName);
             }
             else
             {
                 // create a new file in this file's containing directory
                 string parentDir = SelectedFilePath.Substring(0, SelectedFilePath.Length - file.Name.Length).Replace("\\", "/").Trim();
                 UploadFolder(openFolder.SelectedPath, parentDir + folderName);
             }
             Enabled = true;
         }
     }
 }
Exemple #2
0
        private void saveAsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // SAVE AS...
            Enabled = false;

            NodeFile node = (NodeFile)treeView1.SelectedNode.Tag;

            if (node.IsDirectory)
            {
                using (FolderBrowserDialog openFolder = new FolderBrowserDialog {
                    ShowNewFolderButton = true, Description = "Select where to save the folder..."
                })
                {
                    if (openFolder.ShowDialog() == DialogResult.OK)
                    {
                        DownloadFolder(SelectedFilePath.Replace("\\", "/").Trim(), Path.Combine(openFolder.SelectedPath, node.Name == "/" ? "root" : node.Name));
                    }
                }
            }
            else
            {
                using (SaveFileDialog saveFile = new SaveFileDialog {
                    Title = "Select where to save the file...", FileName = node.Name, OverwritePrompt = true
                })
                {
                    if (saveFile.ShowDialog() == DialogResult.OK)
                    {
                        string selectedFile = SelectedFilePath.Trim().Replace('\\', '/').Trim();
                        Download(selectedFile, saveFile.FileName);
                    }
                }
            }

            Enabled = true;
        }
Exemple #3
0
        private void refreshToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            NodeFile file = (NodeFile)treeView1.SelectedNode.Tag;
            string   path = SelectedFilePath.Replace("\\", "/").Trim();

            if (file.IsDirectory)
            {
                List(path);
            }
            else
            {
                List(path.Substring(0, path.Length - file.Name.Length));
            }
        }
Exemple #4
0
        private void newFolderToolStripMenuItem_Click(object sender, EventArgs eventArgs)
        {
            Enabled = false;

            string selectedFile = SelectedFilePath.Trim();

            if (this.ShowPrompt("Folder name:", $"Create new folder: \\{selectedFile}", out string fileName, deniedChars: "/\\;:*?\"<>|!@#$%^&()+-,`~") == DialogResult.OK)
            {
                NodeFile file = (NodeFile)treeView1.SelectedNode.Tag;
                if (file.IsDirectory)
                {
                    // create the new directory in this directory
                    Device.CreateDirectory(string.Format("{0}/{1}", treeView1.SelectedNode.FullPath.Replace("\\", "/").Trim(), fileName));
                    treeView1.SelectedNode.Nodes.Add(new TreeNode(fileName, new TreeNode[] { new TreeNode("")
                                                                                             {
                                                                                                 Tag = null
                                                                                             } })
                    {
                        Tag = new NodeFile {
                            Name = fileName, IsDirectory = true
                        }
                    });
                }
                else
                {
                    // create the new directory in this file's containing directory
                    string parentDir = treeView1.SelectedNode.FullPath.Substring(1, treeView1.SelectedNode.FullPath.Length - file.Name.Length - 1);
                    Device.CreateDirectory(string.Format("{0}/{1}", parentDir.Replace("\\", "/").Trim(), fileName));
                    GetPathNode(parentDir).Nodes.Add(new TreeNode(fileName, new TreeNode[] { new TreeNode("")
                                                                                             {
                                                                                                 Tag = null
                                                                                             } })
                    {
                        Tag = new NodeFile {
                            Name = fileName, IsDirectory = true
                        }
                    });
                }
            }

            Enabled = true;
        }
Exemple #5
0
        private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // delete
            NodeFile file = (NodeFile)treeView1.SelectedNode.Tag;

            if (MessageBox.Show(string.Format("Are you sure you want to remove the {0} at '{1}'?\nYou can't undo this action.", file.IsDirectory ? "directory" : "file", SelectedFilePath.Replace("\\", "/").Trim()), "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
            {
                Enabled = false;
                if (file.IsDirectory)
                {
                    Device.DeleteDirectory(SelectedFilePath.Replace("\\", "/").Trim());
                }
                else
                {
                    Device.DeleteFile(SelectedFilePath.Replace("\\", "/").Trim());
                }
                treeView1.SelectedNode.Remove();
                Enabled = true;
            }
        }
Exemple #6
0
 private void uploadFileToolStripMenuItem_Click(object sender, EventArgs e)
 {
     // upload file
     using (OpenFileDialog openFile = new OpenFileDialog {
         AddExtension = true, CheckFileExists = true, Multiselect = true, Title = "Select file(s) to upload..."
     })
     {
         if (openFile.ShowDialog() == DialogResult.OK)
         {
             Enabled = false;
             NodeFile node      = (NodeFile)treeView1.SelectedNode.Tag;
             string   uploadDir = (node.IsDirectory ? SelectedFilePath.Replace("\\", "/").Trim() : SelectedFilePath.Substring(1, SelectedFilePath.Length - node.Name.Length - 1)) + "/";
             foreach (string file in openFile.FileNames)
             {
                 string fileName = Path.GetFileName(file);
                 Upload(file, uploadDir + fileName);
             }
             Enabled = true;
         }
     }
 }