線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1637
推到 Plurk!
推到 Facebook!

C#傳檔問題

尚未結案
donken
一般會員


發表:9
回覆:7
積分:3
註冊:2005-07-26

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-07-29 21:54:41 IP:220.131.xxx.xxx 未訂閱
Sever端(封包發送成功--有發送出去) private void button1_Click(object sender, System.EventArgs e) { OpenFileDialog openFileDialog1 = new OpenFileDialog(); openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*" ; openFileDialog1.FilterIndex = 1 ; openFileDialog1.RestoreDirectory = true ; if(openFileDialog1.ShowDialog() == DialogResult.OK) { // Insert code to read the stream here. if(textBox2.TextLength == 0) { FileInfo decideSendFile = new FileInfo(openFileDialog1.FileName); textBox2.Text = "傳送檔案於:" "\t\n" decideSendFile.FullName; } else { FileInfo decideSendFile = new FileInfo(openFileDialog1.FileName); textBox2.Text = textBox2.Text "\t\n " "傳送檔案於:" "\t\n" decideSendFile.FullName; } } //.............................................傳送所選取的檔案............................................. try { FileInfo SendFile = new FileInfo(openFileDialog1.FileName); string SendFileName = SendFile.Name; byte[] fin = Encoding.ASCII.GetBytes(SendFileName.ToCharArray()); client.Send(fin); FileStream fsn = new FileStream(SendFile.FullName, FileMode.Open, FileAccess.Read); byte[] ffin = new Byte[fsn.Length]; fsn.Read(ffin,0,ffin.Length); client.Send(ffin); } catch(SocketException se ) { textBox1.Text = se.ToString(); } } Client端(還未寫完整--請大家指點一下) private void RecvFile_Click(object sender, System.EventArgs e) { SaveFileDialog saveFileDialog1 = new SaveFileDialog(); saveFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*" ; saveFileDialog1.FilterIndex = 1 ; saveFileDialog1.RestoreDirectory = true ; byte[] rec_filetobyte= new byte[1024]; client.Receive(rec_filetobyte); string Rec_filetostring=Encoding.ASCII.GetString (rec_filetobyte); if(saveFileDialog1.ShowDialog() == DialogResult.OK) { // Code to write the stream goes here. FileStream newfs = new FileStream (@"C:\test.txt",FileMode.OpenOrCreate ); BinaryWriter bw = new BinaryWriter (newfs); bw.Write (Rec_filetostring); } } 在clinet端需要怎ㄇ改阿 我原本的想法是: 1.接收 2.將byte-->string 3.開檔 4.將string寫入檔 5.存檔 請大家給我指點一下吧
系統時間:2024-05-14 23:24:20
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!