十年網(wǎng)站開發(fā)經(jīng)驗 + 多家企業(yè)客戶 + 靠譜的建站團隊
量身定制 + 運營維護+專業(yè)推廣+無憂售后,網(wǎng)站問題一站解決
當然不能~! Me.OpenFileDialog1. FileNames這個是多選文件時,一個文件數(shù)組, 不是單個文件,單個文件用Me. OpenFileDialog1.FileName 而Str(Me.OpenFileDialog1. FileNames) 又是什么意思呢~?把數(shù)組轉(zhuǎn)化成字符串~?~~?~? strFileDirectary = Me.OpenFileDialog1.FileName 這樣strFileDirectary 得到的是完整的文件路徑,不是文件夾 我搞不懂你到底要獲得文件路徑還是文件所在的文件夾~~?~?

鼓樓網(wǎng)站建設公司創(chuàng)新互聯(lián)建站,鼓樓網(wǎng)站設計制作,有大型網(wǎng)站制作公司豐富經(jīng)驗。已為鼓樓超過千家提供企業(yè)網(wǎng)站建設服務。企業(yè)網(wǎng)站搭建\外貿(mào)營銷網(wǎng)站建設要多少錢,請找那個售后服務好的鼓樓做網(wǎng)站的公司定做!
希望采納
下載,直接通過url讀取文件,然后Response.OutputStream.Write()數(shù)據(jù)
下面提供個下載的靜態(tài)方法,是C#的,供參考:
///?summary
///?下載文件
///?/summary
///?param?name="fileName"下載的文件名稱(包括擴展名)/param
///?param?name="filePath"下載文件的絕對路徑/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;?//每次實際讀取的字節(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;
}
}????????????????//關閉該文件???????????????
Reader.Close();
}
QQ:121一九五五121
獲取方法,參考實例如下:
'獲取路徑名各部分:
如:
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
'獲取文件名但不包括擴展名
aaa
Public
Function
GetFileNameNoExt(FilePathFileName
As
String)
As
String
'獲取文件名但不包括擴展名
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
'=====
'獲取擴展名
.txt
Public
Function
GetFileExtName(FilePathFileName
As
String)
As
String
'獲取擴展名
.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
選擇文件夾??在工具箱?-?對話框?里選擇?FolderBrowserDialog?添加?到設計器中
然后?代碼寫在??按鈕事件里
FolderBrowserDialog1.ShowDialog()
textbox1.text?=FolderBrowserDialog1.SelectedPath
選擇文件?在工具箱?-?對話框?里選擇?OpenFileDialog
把?OpenFileDialog1.ShowDialog()
TextBox1.Text?=?OpenFileDialog1.FileName
寫到按鈕事件下
如圖
點擊按鈕會彈出?通用對話框??選擇好路徑后?確定?,編輯框里就會顯示選擇的路徑