파일 경로를 입력하면 해당 파일의 MD5 Hash를 스트링으로 반환해준다.


스코드

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Imports System.Security.Cryptography
Public Function GetMD5Hash(ByVal sFilePath As String) As String
     Dim RD As FileStream = New FileStream(sFilePath, FileMode.Open, FileAccess.Read, FileShare.Read)
     RD = New FileStream(sFilePath, FileMode.Open, FileAccess.Read, FileShare.Read)
     Dim md5 As MD5CryptoServiceProvider = New MD5CryptoServiceProvider
     md5.ComputeHash(RD)
     RD.Close()
     Dim hash As Byte() = md5.Hash
     Dim SB As StringBuilder = New StringBuilder
     Dim HB As Byte
     For Each HB In hash
          SB.Append(String.Format("{0:X1}", HB))
     Next
     Return SB.ToString
End Function


사용예제

1
2
Dim sHash as String
sHash = GetMD5Hash("C:\Test.txt")


컨트롤 이름으로 컨트롤 객체를 반환 받을 수 있다.


소스코드

1
2
3
4
5
6
7
8
9
10
11
12
13
Public Module ControlSelectorExtension
    <System.Runtime.CompilerServices.Extension()>
    Public Function FindByName(Of T)(targetClass As Object, name As String) As T
        Dim info As Reflection.PropertyInfo = targetClass.GetType().GetProperty(name, Reflection.BindingFlags.Instance Or Reflection.BindingFlags.NonPublic)
        Return DirectCast(info.GetValue(targetClass, Nothing), T)
    End Function
    <System.Runtime.CompilerServices.Extension()>
    Public Function FindByName(Of T)(name As String, targetClass As Object) As T
        Dim info As Reflection.PropertyInfo = targetClass.GetType().GetProperty(name, Reflection.BindingFlags.Instance Or Reflection.BindingFlags.NonPublic)
        Return DirectCast(info.GetValue(targetClass, Nothing), T)
    End Function
End Module

출처 : http://www.devpia.com/MAEUL/Contents/Detail.aspx?BoardID=45&MAEULNO=18&no=509&page=1

'프로그래밍 > VB.net' 카테고리의 다른 글

VB.net - 파일의 MD5 Hash 값 추출  (0) 2015.05.11
VB.net - 문자열로 Form 객체 반환 받기  (0) 2015.05.11

문자열로 해당 문자열을 name으로 가지고 있는 FORM 객체를 반환해준다.


소스코드

1
2
3
4
5
6
7
8
9
Public Class ObjectFinder
    Public Shared Function GetFormByName(ByVal formName As String) As Form
            Dim assemblyName As String = _
            [Assembly].GetEntryAssembly().GetName.Name.Replace(" ", "_")
            Dim myType As Type = _
                Type.GetType(assemblyName & "." & formName)
            Return CType(Activator.CreateInstance(myType), Form)
    End Function
End Class


사용예제 (Form1의 객체를 받아오기)

1
2
dim frmTEST as Form
frmTEST = ObjectFinder.GetFormByName("Form1")



'프로그래밍 > VB.net' 카테고리의 다른 글

VB.net - 파일의 MD5 Hash 값 추출  (0) 2015.05.11
VB.net - 컨트롤 이름으로 컨트롤 접근  (0) 2015.05.11

+ Recent posts