當(dāng)然不能~! Me.OpenFileDialog1. FileNames這個(gè)是多選文件時(shí),一個(gè)文件數(shù)組, 不是單個(gè)文件,單個(gè)文件用Me. OpenFileDialog1.FileName 而Str(Me.OpenFileDialog1. FileNames) 又是什么意思呢~?把數(shù)組轉(zhuǎn)化成字符串~?~~?~? strFileDirectary = Me.OpenFileDialog1.FileName 這樣strFileDirectary 得到的是完整的文件路徑,不是文件夾 我搞不懂你到底要獲得文件路徑還是文件所在的文件夾~~?~?
鼓樓網(wǎng)站建設(shè)公司創(chuàng)新互聯(lián)建站,鼓樓網(wǎng)站設(shè)計(jì)制作,有大型網(wǎng)站制作公司豐富經(jīng)驗(yàn)。已為鼓樓超過(guò)千家提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\外貿(mào)營(yíng)銷網(wǎng)站建設(shè)要多少錢,請(qǐng)找那個(gè)售后服務(wù)好的鼓樓做網(wǎng)站的公司定做!
希望采納
下載,直接通過(guò)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)
{
//打開(kāi)要下載的文件,并把該文件存放在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)
{????
//客戶端瀏覽器還打開(kāi)著,繼續(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)斷開(kāi),阻止繼續(xù)循環(huán)????????????????????????
Length?=?-1;
}
}????????????????//關(guān)閉該文件???????????????
Reader.Close();
}
QQ:121一九五五121
獲取方法,參考實(shí)例如下:
'獲取路徑名各部分:
如:
c:\dir1001\aaa.txt
'獲取路徑路徑
c:\dir1001\
Public
Function
GetFileName(FilePathFileName
As
String)
As
String
'獲取文件名
aaa.txt
On
Error
Resume
Next
Dim
i
As
Integer,
J
As
Integer
i
Len(FilePathFileName)
J
InStrRev(FilePathFileName,
"\")
GetFileName
Mid(FilePathFileName,
J
+
1,
i)
End
Function
''獲取路徑路徑
c:\dir1001\
Public
Function
GetFilePath(FilePathFileName
As
String)
As
String
'獲取路徑路徑
c:\dir1001\
On
Error
Resume
Next
Dim
J
As
Integer
J
InStrRev(FilePathFileName,
"\")
GetFilePath
Mid(FilePathFileName,
1,
J)
End
Function
'獲取文件名但不包括擴(kuò)展名
aaa
Public
Function
GetFileNameNoExt(FilePathFileName
As
String)
As
String
'獲取文件名但不包括擴(kuò)展名
aaa
On
Error
Resume
Next
Dim
i
As
Integer,
J
As
Integer,
k
As
Integer
i
Len(FilePathFileName)
J
InStrRev(FilePathFileName,
"\")
k
InStrRev(FilePathFileName,
".")
If
k
Then
GetFileNameNoExt
Mid(FilePathFileName,
J
+
1,
i
-
J)
Else
GetFileNameNoExt
Mid(FilePathFileName,
J
+
1,
k
-
J
-
1)
End
If
End
Function
'=====
'獲取擴(kuò)展名
.txt
Public
Function
GetFileExtName(FilePathFileName
As
String)
As
String
'獲取擴(kuò)展名
.txt
On
Error
Resume
Next
Dim
i
As
Integer,
J
As
Integer
i
Len(FilePathFileName)
J
InStrRev(FilePathFileName,
".")
If
J
Then
GetFileExtName
".txt"
Else
GetFileExtName
Mid(FilePathFileName,
J,
i)
End
If
End
Function
選擇文件夾??在工具箱?-?對(duì)話框?里選擇?FolderBrowserDialog?添加?到設(shè)計(jì)器中
然后?代碼寫在??按鈕事件里
FolderBrowserDialog1.ShowDialog()
textbox1.text?=FolderBrowserDialog1.SelectedPath
選擇文件?在工具箱?-?對(duì)話框?里選擇?OpenFileDialog
把?OpenFileDialog1.ShowDialog()
TextBox1.Text?=?OpenFileDialog1.FileName
寫到按鈕事件下
如圖
點(diǎn)擊按鈕會(huì)彈出?通用對(duì)話框??選擇好路徑后?確定?,編輯框里就會(huì)顯示選擇的路徑
新聞名稱:vb.net文件路徑 vb當(dāng)前目錄路徑
網(wǎng)頁(yè)路徑:http://aaarwkj.com/article42/docjphc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供面包屑導(dǎo)航、網(wǎng)站排名、微信公眾號(hào)、企業(yè)網(wǎng)站制作、響應(yīng)式網(wǎng)站、服務(wù)器托管
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)