コード例 #1
0
        /// <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(() =>
                {
                    Cursor          = Cursors.WaitCursor;
                    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);
                    }
                    file.Close();
                    Cursor = Cursors.Default;
                }));
            }

            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> (" + KichThuocFile.SizeSuffix(new FileInfo(filename).Length) + ")";

            return(s);
        }
コード例 #2
0
        /// <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> (" + KichThuocFile.SizeSuffix(new FileInfo(path).Length) + ")";

            SendMessage(content, path);
        }