private void UploadButton_Click(object sender, EventArgs e) { OpenFileDialog dlg = new OpenFileDialog() { Title = "Select a file to upload", RestoreDirectory = true, CheckFileExists = true }; dlg.ShowDialog(); if (!string.IsNullOrEmpty(dlg.FileName)) { //file name string virtualPath = Path.GetFileName(dlg.FileName); FileStream objfilestream = new FileStream(dlg.FileName, FileMode.Open, FileAccess.Read); int len = (int)objfilestream.Length; Byte[] mybytearray = new Byte[len]; objfilestream.Read(mybytearray, 0, len); FileTransfer.FileTransferSoapClient myservice = new FileTransfer.FileTransferSoapClient(); myservice.SaveDocument(mybytearray, virtualPath); objfilestream.Close(); RefreshFileList(currentuser); } }
//new folder private void button1_Click(object sender, EventArgs e) { try { if (treeView1.SelectedNode != null) { TreeNode tempNode = treeView1.SelectedNode; string path = "\\" + tempNode.Text; while (tempNode.Parent != null) { tempNode = tempNode.Parent; path = path.Insert(0, "\\" + tempNode.Text); } string defaultNmae = "Folder Name"; if (InputBox("New Folder Nmae", "", ref defaultNmae) == DialogResult.OK) { FileTransfer.FileTransferSoapClient myservice = new FileTransfer.FileTransferSoapClient(); bool result = myservice.NewFolder(path + "\\" + defaultNmae); if (!result) { MessageBox.Show("Folder alrealy exists"); } RefreshFileList(currentuser); } } else { MessageBox.Show("Please select a root folder"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void Login_Click(object sender, EventArgs e) { try { FileTransfer.FileTransferSoapClient myservice = new FileTransfer.FileTransferSoapClient(); bool bResult = myservice.LoginUser(textBox1.Text); if (!bResult) { MessageBox.Show("Login Success"); login = true; currentuser = textBox1.Text; RefreshFileList(currentuser); return; } else if (bResult) { MessageBox.Show("User no find"); return; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void DownloadButton_Click(object sender, EventArgs e) { try { if (treeView1.SelectedNode != null) { string fileName = treeView1.SelectedNode.Text; //Ask where it should be saved SaveFileDialog dlg = new SaveFileDialog() { RestoreDirectory = true, OverwritePrompt = true, Title = "Save as...", FileName = fileName }; dlg.ShowDialog(this); if (!string.IsNullOrEmpty(dlg.FileName)) { TreeNode tempNode = treeView1.SelectedNode; string path = "\\" + tempNode.Text; while (tempNode.Parent != null) { tempNode = tempNode.Parent; path = path.Insert(0, "\\" + tempNode.Text); } // Get the file from the server MemoryStream objstreaminput = new MemoryStream(); FileStream objfilestream = new FileStream(Path.GetFullPath(dlg.FileName), FileMode.Create, FileAccess.ReadWrite); FileTransfer.FileTransferSoapClient myservice = new FileTransfer.FileTransferSoapClient(); int len = (int)myservice.GetDocumentLen(path); Byte[] mybytearray = new Byte[len]; mybytearray = myservice.GetDocument(path); objfilestream.Write(mybytearray, 0, len); objfilestream.Close(); } } else { MessageBox.Show("Please select a file"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void Register_Click(object sender, EventArgs e) { FileTransfer.FileTransferSoapClient myservice = new FileTransfer.FileTransferSoapClient(); bool bResult = myservice.NewUser(textBox1.Text); if (!bResult) { MessageBox.Show("User name already exisits, please login"); return; } MessageBox.Show("Register Success"); login = true; currentuser = textBox1.Text; RefreshFileList(textBox1.Text); }
private void UploadButton_Click(object sender, EventArgs e) { try { if (treeView1.SelectedNode != null) { OpenFileDialog dlg = new OpenFileDialog() { Title = "Select a file to upload", RestoreDirectory = true, CheckFileExists = true }; dlg.ShowDialog(); if (!string.IsNullOrEmpty(dlg.FileName)) { TreeNode tempNode = treeView1.SelectedNode; string path = "\\" + tempNode.Text; while (tempNode.Parent != null) { tempNode = tempNode.Parent; path = path.Insert(0, "\\" + tempNode.Text); } //file name string fileName = Path.GetFileName(dlg.FileName); FileStream objfilestream = new FileStream(dlg.FileName, FileMode.Open, FileAccess.Read); int len = (int)objfilestream.Length; Byte[] mybytearray = new Byte[len]; objfilestream.Read(mybytearray, 0, len); FileTransfer.FileTransferSoapClient myservice = new FileTransfer.FileTransferSoapClient(); myservice.SaveDocument(mybytearray, fileName, path); objfilestream.Close(); RefreshFileList(currentuser); } } else { MessageBox.Show("Please select a folder"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void RefreshFileList(string username) { //To do FileTransfer.FileTransferSoapClient myservice = new FileTransfer.FileTransferSoapClient(); string temp = myservice.GetFileStruture(username); XElement xml = new XElement(XElement.Parse(temp)); XmlDataDocument xmldoc = new XmlDataDocument(); xmldoc.LoadXml(xml.ToString()); XmlNode xmlnode; xmlnode = xmldoc.FirstChild; treeView1.Nodes.Clear(); treeView1.Nodes.Add(new TreeNode(xmldoc.DocumentElement.GetAttribute("Name"))); TreeNode tNode; tNode = treeView1.Nodes[0]; AddNode(xmlnode, tNode); }
private void DeleteButton_Click(object sender, EventArgs e) { try { if (treeView1.SelectedNode != null) { TreeNode tempNode = treeView1.SelectedNode; string path = "\\" + tempNode.Text; if (tempNode.Parent != null) { //confirm box var confirmResult = MessageBox.Show("Are you sure to delete " + tempNode.Text + "??", "Confirm Delete!!", MessageBoxButtons.YesNo); if (confirmResult == DialogResult.Yes) { while (tempNode.Parent != null) { tempNode = tempNode.Parent; path = path.Insert(0, "\\" + tempNode.Text); } FileTransfer.FileTransferSoapClient myservice = new FileTransfer.FileTransferSoapClient(); myservice.DeleteDocument(path); RefreshFileList(currentuser); } } else { MessageBox.Show("Cannot delete root folder"); } } else { MessageBox.Show("Please select a file"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }