//Запрос на загрузку файла protected internal void LoadFile() { InfoFile info = new InfoFile(); info.FileName = view.GetUser.Message; if (string.IsNullOrEmpty(info.FileName)) { return; } byte[] data = info.Serialize(); streamSharing.Write(data, 0, data.Length); }
private void SendFile(InfoFile info) { try { FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read); info.FileLenght = fs.Length; byte[] data = info.Serialize(); streamSharing.Write(data, 0, data.Length); data = new byte[fs.Length]; fs.Read(data, 0, (int)fs.Length); fs.Close(); streamSharing.Write(data, 0, data.Length); } catch (Exception ex) { MessageBox.Show(ex.Message + "SendFile"); } }
protected internal void SendFile(bool flag) { try { InfoFile info = new InfoFile(); OpenFileDialog dialog = new OpenFileDialog(); if (dialog.ShowDialog() == true) { info.FileName = dialog.SafeFileName; filePath = dialog.FileName; if (flag) { info.PrivateName = view.SelectUser; } SendFile(info); } } catch (Exception ex) { MessageBox.Show(ex.Message + "SendFile"); } }
protected internal void ReceiveSharing() { try { while (true) { byte[] data = new byte[256]; InfoFile info = new InfoFile(); do { streamSharing.Read(data, 0, data.Length); info.Desserialize(data); int len = (int)info.FileLenght; int size = 0; FileStream fs = new FileStream(info.FileName, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite, len); do { data = new byte[1024000]; size = streamSharing.Read(data, 0, data.Length); fs.Write(data, 0, size); if (fs.Length == len) { break; } } while (size > 0); fs.Close(); streamSharing.Flush(); } while (streamSharing.DataAvailable); } } catch (Exception ex) { Close(); } }