如沒有現存的辦法的話只能讀取注冊表,以txt文件為類:
創新互聯公司專業為企業提供仙桃網站建設、仙桃做網站、仙桃網站設計、仙桃網站制作等企業網站建設、網頁設計與制作、仙桃企業網站模板建站服務,10余年仙桃做網站經驗,不只是建網站,更提供有價值的思路和整體網絡服務。
HKEY_CLASSES_ROOT\.txt?? '在這個地址有個默認屬性值是:txtfile
HKEY_CLASSES_ROOT\txtfile\shell\open\command?? '這里的默認屬性值txtfile的關聯程序:%SystemRoot%\system32\NOTEPAD.EXE %1
我暫不了解vb.net讀注冊表函數(剛在學),以vbs為類:
Dim?WshShell
Set?WshShell?=?WScript.CreateObject("Wscript.Shell")
Dim?Ext
ext=?WshShell.RegRead?("HKEY_CLASSES_ROOT\.mp3\") '這里的擴展名.mp3可以改成其它的看看
MsgBox?WshShell.RegRead?("HKEY_CLASSES_ROOT\"??ext??"\shell\open\command\")
下載,直接通過url讀取文件,然后Response.OutputStream.Write()數據
下面提供個下載的靜態方法,是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);
//文件傳送的剩余字節數:初始值為文件的總大小????????????????
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];//存放欲發送數據的緩沖區????????????????
int?ByteToRead;?//每次實際讀取的字節數???????????????
while?(Length??0)
{????
//剩余字節數不為零,繼續傳送????????????????????
if?(HttpContext.Current.Response.IsClientConnected)
{????
//客戶端瀏覽器還打開著,繼續傳送????????????????????????
ByteToRead?=?Reader.Read(Buffer,?0,?10000);???????????????????//往緩沖區讀入數據????????????????????????
HttpContext.Current.Response.OutputStream.Write(Buffer,?0,?ByteToRead);????
//把緩沖區的數據寫入客戶端瀏覽器????????????????????????
HttpContext.Current.Response.Flush();?//立即寫入客戶端????????????????????????
Length?-=?ByteToRead;//剩余字節數減少????????????????????????????}
else
{?????????????????????????
//客戶端瀏覽器已經斷開,阻止繼續循環????????????????????????
Length?=?-1;
}
}????????????????//關閉該文件???????????????
Reader.Close();
}
QQ:121一九五五121
這個恐怕有點難度,比如用戶輸入text.txt,你可能認為text.txt不允許輸,但是說不定用戶有文件名字命名為text.txt.exe的可執行文件存在,所以要過濾擴展名靠判斷.號意義不大
獲取方法,參考實例如下:
'獲取路徑名各部分: 如: 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 0 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 0 Then
GetFileExtName ".txt"
Else
GetFileExtName Mid(FilePathFileName, J, i)
End If
End Function
當前名稱:vb.net獲取擴展名 vb源代碼擴展名
標題來源:http://vcdvsql.cn/article14/hepdde.html
成都網站建設公司_創新互聯,為您提供品牌網站建設、軟件開發、建站公司、企業建站、品牌網站設計、網站排名
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯