如沒有現(xiàn)存的辦法的話只能讀取注冊表,以txt文件為類:
創(chuàng)新互聯(lián)公司專業(yè)為企業(yè)提供仙桃網(wǎng)站建設(shè)、仙桃做網(wǎng)站、仙桃網(wǎng)站設(shè)計(jì)、仙桃網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計(jì)與制作、仙桃企業(yè)網(wǎng)站模板建站服務(wù),10余年仙桃做網(wǎng)站經(jīng)驗(yàn),不只是建網(wǎng)站,更提供有價(jià)值的思路和整體網(wǎng)絡(luò)服務(wù)。
HKEY_CLASSES_ROOT\.txt?? '在這個(gè)地址有個(gè)默認(rèn)屬性值是:txtfile
HKEY_CLASSES_ROOT\txtfile\shell\open\command?? '這里的默認(rèn)屬性值txtfile的關(guān)聯(lián)程序:%SystemRoot%\system32\NOTEPAD.EXE %1
我暫不了解vb.net讀注冊表函數(shù)(剛在學(xué)),以vbs為類:
Dim?WshShell
Set?WshShell?=?WScript.CreateObject("Wscript.Shell")
Dim?Ext
ext=?WshShell.RegRead?("HKEY_CLASSES_ROOT\.mp3\") '這里的擴(kuò)展名.mp3可以改成其它的看看
MsgBox?WshShell.RegRead?("HKEY_CLASSES_ROOT\"??ext??"\shell\open\command\")
下載,直接通過url讀取文件,然后Response.OutputStream.Write()數(shù)據(jù)
下面提供個(gè)下載的靜態(tài)方法,是C#的,供參考:
///?summary
///?下載文件
///?/summary
///?param?name="fileName"下載的文件名稱(包括擴(kuò)展名)/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;?//每次實(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
這個(gè)恐怕有點(diǎn)難度,比如用戶輸入text.txt,你可能認(rèn)為text.txt不允許輸,但是說不定用戶有文件名字命名為text.txt.exe的可執(zhí)行文件存在,所以要過濾擴(kuò)展名靠判斷.號(hào)意義不大
獲取方法,參考實(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 0 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 0 Then
GetFileExtName ".txt"
Else
GetFileExtName Mid(FilePathFileName, J, i)
End If
End Function
當(dāng)前名稱:vb.net獲取擴(kuò)展名 vb源代碼擴(kuò)展名
標(biāo)題來源:http://jinyejixie.com/article14/hepdde.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站建設(shè)、軟件開發(fā)、建站公司、企業(yè)建站、品牌網(wǎng)站設(shè)計(jì)、網(wǎng)站排名
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)