如何使用带有vb.net的asp.net查找驱动器号 [英] how to find the drive letter using asp.net with vb.net

查看:72
本文介绍了如何使用带有vb.net的asp.net查找驱动器号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想找到包含特定文件或文件夹的可移动驱动器(i:,g:,h:).为此,我正在使用此代码.

I want to find the Removable drive(i:,g:,h: ) which contains a specific File or folder. For that i am using this code.

Imports System.Web.UI.WebControls
Imports System.Web.UI
Imports System.Web
Imports System.IO
Imports System.ComponentModel
Imports System.Text
Imports System.Windows.Forms.MessageBox
Imports System.Runtime.InteropServices
Imports System.Windows.Forms

Namespace Download
    Public Class Downloadfiles
        Inherits System.Web.UI.Page
        Private Const WM_DEVICECHANGE As Integer = &H219
        Private Const DBT_DEVICEARRIVAL As Integer = &H8000
        Private Const DBT_DEVTYP_VOLUME As Integer = &H2

        'Device information structure
        Public Structure DEV_BROADCAST_HDR
            Public dbch_size As Int32
            Public dbch_devicetype As Int32
            Public dbch_reserved As Int32
        End Structure

        'Volume information Structure
        Private Structure DEV_BROADCAST_VOLUME
            Public dbcv_size As Int32
            Public dbcv_devicetype As Int32
            Public dbcv_reserved As Int32
            Public dbcv_unitmask As Int32
            Public dbcv_flags As Int16
        End Structure
        Private Function GetDriveLetterFromMask(ByRef Unit As Int32) As Char
            For i As Integer = 0 To 25
                If Unit = (2 ^ i) Then
                    Return Chr(Asc("A") + i)
                End If
            Next
        End Function


        'Override message processing to check for the DEVICECHANGE message
        Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
            If m.Msg = WM_DEVICECHANGE Then
                If CInt(m.WParam) = DBT_DEVICEARRIVAL Then
                    Dim DeviceInfo As DEV_BROADCAST_HDR
                    DeviceInfo = DirectCast(Marshal.PtrToStructure(m.LParam, GetType(DEV_BROADCAST_HDR)), DEV_BROADCAST_HDR)
                    If DeviceInfo.dbch_devicetype = DBT_DEVTYP_VOLUME Then
                        Dim Volume As DEV_BROADCAST_VOLUME
                        Volume = DirectCast(Marshal.PtrToStructure(m.LParam, GetType(DEV_BROADCAST_VOLUME)), DEV_BROADCAST_VOLUME)
                        Dim DriveLetter As String = (GetDriveLetterFromMask(Volume.dbcv_unitmask) & ":\")
                        If IO.File.Exists(IO.Path.Combine(DriveLetter, "test.txt")) Then
                            '<<<< The test file has been found >>>>
                            MessageBox.Show("Found test file")
                        Else
                            '<<<< Test file has not been found >>>>
                            MessageBox.Show("Could not find test file")
                        End If
                    End If
                End If
            End If
            MyBase.WndProc(m)
        End Sub
    End Class
End Namespace


此代码在vb.net中有效,但在Visual Studio中不起作用.当我尝试与asp.net集成时,它在重写方法中显示错误.错误在此行中显示受保护的替代子WndProc(由System.Windows.Forms.Message传递的ByRef M)"请帮助我.


This code works in vb.net but it is not working in visual studio. when i am trying to integrate with asp.net it shows an error in override method. error shows in this line "Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)" Please help me.

推荐答案

http://msdn.microsoft.com/en-us/library/system.windows.forms.form.wndproc.aspx [ ^ ]
About Window Procedures WndProc[^]
http://msdn.microsoft.com/en-us/library/system.windows.forms.form.wndproc.aspx[^]


这篇关于如何使用带有vb.net的asp.net查找驱动器号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆