新聞中心
求VB.NET獲取文件路徑的方法
Dim my_path() As String = System.IO.Directory.GetFiles("d:\", "文件名", IO.SearchOption.AllDirectories)
創(chuàng)新互聯(lián)建站作為成都網(wǎng)站建設(shè)公司,專注成都網(wǎng)站建設(shè)、網(wǎng)站設(shè)計(jì),有關(guān)成都企業(yè)網(wǎng)站建設(shè)方案、改版、費(fèi)用等問題,行業(yè)涉及雨棚定制等多個(gè)領(lǐng)域,已為上千家企業(yè)服務(wù),得到了客戶的尊重與認(rèn)可。
因?yàn)橛锌赡茉诙鄠€(gè)地方,所以進(jìn)行了全盤搜索,歌曲的所有地址路徑在數(shù)組my_path中
vb點(diǎn)虐 d盤有個(gè)文件夾file里面有excel類型文件怎么用getfile取到文件的路徑
你好,請(qǐng)使用System.IO.Directory.EnumerateFiles()方法
Dim?XLS文件列表?As?IEnumerable(Of?string)
Dim?XLSX文件列表?As?IEnumerable(Of?string)
Dim?path?As?String?=?"D:\File\"
XLS文件列表?=?Directory.EnumerateFiles(path,?"*.xls",?SearchOption.TopDirectoryOnly)
XLSX文件列表?=?Directory.EnumerateFiles(path,?"*.xlsx",?SearchOption.TopDirectoryOnly)
vb點(diǎn)虐 文件關(guān)聯(lián)后獲取文件路徑
我沒有設(shè)置關(guān)聯(lián),只是把文件拖到程序文件上打開,應(yīng)該是一樣的。
主要是看程序啟動(dòng)時(shí)的命令行參數(shù)My.Application.CommandLineArgs,里面包括要打開的文件路徑。
在Sub Main 或者 啟動(dòng)窗口的Load事件里添加代碼
If My.Application.CommandLineArgs.Count 0 AndAlso My.Computer.FileSystem.FileExists(My.Application.CommandLineArgs(0)) Then‘參數(shù)不為空且文件存在
Dim s As New IO.StreamReader(My.Application.CommandLineArgs(0))
MsgBox(s.ReadToEnd)
End If
你還可以處理更多的命令行參數(shù)。
關(guān)于命令行參數(shù)
vb點(diǎn)虐 怎么實(shí)現(xiàn)點(diǎ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();
}
QQ:121一九五五121
新聞名稱:vb點(diǎn)虐 截取文件路徑 vba截取路徑
標(biāo)題來源:http://www.dlmjj.cn/article/ddeopgs.html