Пример #1
0
        private void addNewDirectoryToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog fbd = new FolderBrowserDialog();
            DialogResult result = fbd.ShowDialog();

            string[] files = Directory.GetFiles(fbd.SelectedPath);
            List<FileModel> dirFiles = new List<FileModel>();
            for(int i = 0; i < files.Length; i++)
            {
                FileModel theFile = new FileModel();
                theFile.Path = files[i].ToString();
                theFile.Name = new FileInfo(files[i]).Name;
                theFile.Size = new FileInfo(files[i]).Length;
                dirFiles.Add(theFile);
            }
            StaticValues.self.Files.Add(new DirectoryModel(fbd.SelectedPath, fbd.ToString(), dirFiles));
        }
Пример #2
0
 public bool SendFile(FileModel piFile, UserModel piReciever)
 {
     try
     {
         IPAddress ipaddress = IPAddress.Parse(piReciever.IP);
         client = new TcpClient(new IPEndPoint(ipaddress, 9999));
         FileStream Fs = new FileStream(piFile.Path, FileMode.Open, FileAccess.Read);
         byte[] buffer = StaticMethods.ObjectToByteArray(Fs);
         NetworkStream clientStream = client.GetStream();
         ASCIIEncoding encoder = new ASCIIEncoding();
         clientStream.Write(buffer, 0, buffer.Length);
         clientStream.Flush();
         client.Close();
         return true;
     }
     catch (Exception e)
     {
         return false;
     }
 }