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); } }
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); } }