/// <summary> /// Thực hiện nhận file /// </summary> /// <param name="sr"></param> /// <returns>FileName đã nhận</returns> string DoReciveFile(StreamReader sr) { string filename = sr.ReadLine(); // Tên file lstFileName.Add(filename); int numPacket = Convert.ToInt32(sr.ReadLine()); if (this.InvokeRequired) { this.Invoke(new Action(() => { pnlFile.Visible = true; Cursor = Cursors.WaitCursor; prgFile.Maximum = numPacket; prgFile.Value = 0; FileStream file = new FileStream(filename, FileMode.OpenOrCreate, FileAccess.Write); for (int i = 0; i < numPacket; i++) { string base64 = sr.ReadLine(); // Nội dung file SendingBuffer = System.Convert.FromBase64String(base64); file.Write(SendingBuffer, 0, SendingBuffer.Length); if (prgFile.Value >= prgFile.Maximum) { prgFile.Value = prgFile.Minimum; } prgFile.PerformStep(); lblFile.Text = "Đã nhận " + prgFile.Value + "/" + prgFile.Maximum; } file.Close(); Cursor = Cursors.Default; pnlFile.Visible = false; })); } string path = Directory.GetCurrentDirectory() + "/" + filename; Uri url = new Uri(path); string address = url.AbsoluteUri; string extension = Path.GetExtension(filename).ToLower(); string s = "<a href='" + url.PathAndQuery.Replace(":", "(~*)") + "'>" + ((extension == ".jpg" || extension == ".png") ? "<img src='" + address + "' style='max-width:300px'/><br/>" : "") + "<b>" + filename + "</b></a> (" + FileSize.SizeSuffix(new FileInfo(filename).Length) + ")"; return(s); }
/// <summary> /// Gửi hình ảnh & tập tin đính kèm /// </summary> /// <param name="path"></param> void SendImage(string path) { Uri url = new Uri(path); string address = url.AbsoluteUri; string extension = Path.GetExtension(path).ToLower(); string content = "<a href='" + url.PathAndQuery.Replace(":", "(~*)") + "'>" + ((extension == ".jpg" || extension == ".png") ? "<img src='" + address + "' style='max-width:300px'/><br/>" : "") + "<b>" + Path.GetFileName(path) + "</b></a> (" + FileSize.SizeSuffix(new FileInfo(path).Length) + ")"; SendMessage(content, path); }