Dim OpenFileDialog As New OpenFileDialog
創(chuàng)新互聯(lián)制作網(wǎng)站網(wǎng)頁找三站合一網(wǎng)站制作公司,專注于網(wǎng)頁設(shè)計(jì),網(wǎng)站制作、成都網(wǎng)站制作,網(wǎng)站設(shè)計(jì),企業(yè)網(wǎng)站搭建,網(wǎng)站開發(fā),建網(wǎng)站業(yè)務(wù),680元做網(wǎng)站,已為近1000家服務(wù),創(chuàng)新互聯(lián)網(wǎng)站建設(shè)將一如既往的為我們的客戶提供最優(yōu)質(zhì)的網(wǎng)站建設(shè)、網(wǎng)絡(luò)營銷推廣服務(wù)!
OpenFileDialog.InitialDirectory = My.Computer.FileSystem.SpecialDirectories.MyDocuments
OpenFileDialog.Filter = "文本文件(*.jpg)|*.jpg|所有文件(*.*)|*.*"
If (OpenFileDialog.ShowDialog(Me) = System.Windows.Forms.DialogResult.OK) Then
Dim FileName As String = OpenFileDialog.FileName
' TODO: 在此處添加打開文件的代碼。
textbox1.Text = FileName
End If
第一個(gè)按鈕 上傳
Dim filelast As String = fileaddbefore.Text.Substring(fileaddbefore.Text.LastIndexOf("."), fileaddbefore.Text.Length - fileaddbefore.Text.LastIndexOf("."))
MessageBox.Show(filelast)
My.Computer.Network.UploadFile(textbox1.Text, "" 文件名.Text filelast, "登錄名1", "登錄密碼", True, 100)
第二個(gè)按鈕
接口,你只要引用他給你發(fā)的這個(gè)文件,再實(shí)現(xiàn)他給你的接口就行了。
下載,直接通過url讀取文件,然后Response.OutputStream.Write()數(shù)據(jù)
下面提供個(gè)下載的靜態(tài)方法,是C#的,供參考:
///?summary
///?下載文件
///?/summary
///?param?name="fileName"下載的文件名稱(包括擴(kuò)展名)/param
///?param?name="filePath"下載文件的絕對(duì)路徑/param
public?static?void?DownFile(string?fileName,?string?filePath)
{
//打開要下載的文件,并把該文件存放在FileStream中????????????????
System.IO.FileStream?Reader?=?System.IO.File.OpenRead(filePath);
//文件傳送的剩余字節(jié)數(shù):初始值為文件的總大小????????????????
long?Length?=?Reader.Length;
HttpContext.Current.Response.Buffer?=?false;
HttpContext.Current.Response.AddHeader("Connection",?"Keep-Alive");
HttpContext.Current.Response.ContentType?=?"application/octet-stream";
HttpContext.Current.Response.Charset?=?"utf-8";
HttpContext.Current.Response.AddHeader("Content-Disposition",?"attachment;?filename="?+?System.Web.HttpUtility.UrlEncode(fileName));
HttpContext.Current.Response.AddHeader("Content-Length",?Length.ToString());
byte[]?Buffer?=?new?Byte[10000];//存放欲發(fā)送數(shù)據(jù)的緩沖區(qū)????????????????
int?ByteToRead;?//每次實(shí)際讀取的字節(jié)數(shù)???????????????
while?(Length??0)
{????
//剩余字節(jié)數(shù)不為零,繼續(xù)傳送????????????????????
if?(HttpContext.Current.Response.IsClientConnected)
{????
//客戶端瀏覽器還打開著,繼續(xù)傳送????????????????????????
ByteToRead?=?Reader.Read(Buffer,?0,?10000);???????????????????//往緩沖區(qū)讀入數(shù)據(jù)????????????????????????
HttpContext.Current.Response.OutputStream.Write(Buffer,?0,?ByteToRead);????
//把緩沖區(qū)的數(shù)據(jù)寫入客戶端瀏覽器????????????????????????
HttpContext.Current.Response.Flush();?//立即寫入客戶端????????????????????????
Length?-=?ByteToRead;//剩余字節(jié)數(shù)減少????????????????????????????}
else
{?????????????????????????
//客戶端瀏覽器已經(jīng)斷開,阻止繼續(xù)循環(huán)????????????????????????
Length?=?-1;
}
}????????????????//關(guān)閉該文件???????????????
Reader.Close();
}
My.Computer.Network.UploadFile
比如上傳到FTP
My.Computer.Network.UploadFile("d:\1.txt", "“, "FTP賬號(hào)", "FTP密碼", True, 100)
新手路過。
在窗體上放置一個(gè) Timer 控件,Interval 屬性設(shè)置為 120000(120000毫秒=120秒=2分鐘),Enabled 屬性設(shè)置為 True,添加如下代碼:
Private?Sub?Timer1_Tick(ByVal?sender?As?System.Object,?ByVal?e?As?System.EventArgs)?Handles?Timer1.Tick
Dim?dDir1?As?New?System.IO.DirectoryInfo("C:\a")
dDir1.MoveTo("D:\b")??'移動(dòng)?C:\a?文件夾所有文件到?D:\b????
End?Sub
路徑轉(zhuǎn)成byte數(shù)組,加在文件byte數(shù)組的前頭,用一個(gè)或兩個(gè)byte表示文件路徑byte數(shù)組的大小,加在路徑+文件合并后的byte數(shù)組最前面。
順序:路徑占用字節(jié)+路徑字節(jié)數(shù)組+文件字節(jié)數(shù)組
收到數(shù)據(jù)后,先提取前兩個(gè)字節(jié)表示的長度,再通過長度提取路徑,剩下的是文件。