Esempio n. 1
0
        private void 发送文件ToolStripMenuItem_Click(object sender, EventArgs e)//发送文件
        {
            System.Windows.Forms.OpenFileDialog fd = new OpenFileDialog();
            fd.Multiselect = true;
            fd.Filter      = "所有文件|*.*";
            if (fd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                if (fd.FileName.Length > 0)
                {
                    FileTransferControl FileTransferCon = new FileTransferControl();
                    FileTransferCon.ReceiveOrSend = true;
                    FileTransferCon.MySelefInfo   = Program.MainEntity;
                    FileTransferCon.FrieInfo      = this.me;

                    //发送传输文件消息
                    FileTransferCon.FilePath = fd.FileName;
                    int    IndexNum   = fd.FileName.LastIndexOf('\\', 0);
                    string FileName   = fd.FileName.Substring(IndexNum + 1);
                    long   FileLenth  = new FileInfo(fd.FileName).Length; //获取文件的大小
                    string NewMessage = FileName + "," + FileLenth.ToString();
                    FileTransferCon.FileName = FileName;
                    FileTransferCon.FileSize = int.Parse(FileLenth.ToString());
                    IPEndPoint Localpoint = new IPEndPoint(IPAddress.Parse(this.Tag.ToString()), 8002);
                    HandleMethod.UdpBrodcastSend("FileAplly", NewMessage, Localpoint);

                    FileTransferCon.Parent = panelControl7;
                    FileTransferCon.Dock   = System.Windows.Forms.DockStyle.Fill;
                }
            }
        }
Esempio n. 2
0
        public void ReceiveFile(MessageEntity MessageEx)//被动接受文件方法
        {
            FileTransferControl FileTransferCon = new FileTransferControl();

            FileTransferCon.Name          = "ReceiveCon";
            FileTransferCon.ReceiveOrSend = false;
            FileTransferCon.MySelefInfo   = Program.MainEntity;
            FileTransferCon.FrieInfo      = this.me;

            string[] FileInfoArray = MessageEx.Message.Split(',');
            if (FileInfoArray.Count() >= 2)
            {
                FileTransferCon.FileName = FileInfoArray[0];
                FileTransferCon.FileSize = int.Parse(FileInfoArray[1]);
            }

            FileTransferCon.Parent = panelControl7;
            FileTransferCon.Dock   = System.Windows.Forms.DockStyle.Fill;
        }