Librería de Snippets para VB.NET !! (Compartan aquí sus snippets)

Iniciado por Eleкtro, 18 Diciembre 2012, 22:23 PM

0 Miembros y 4 Visitantes están viendo este tema.

Eleкtro

· Detectar la codificación de un archivo de texto

(Para quien no entienda de BOM's y codificaciones, no existe una manera 100% fiable de detectar la codificación y puede dar falsos positivos)


Código (vbnet) [Seleccionar]
#Region " Detect Text Encoding "

   ' [ Detect Text Encoding Function ]
   '
   ' Examples :
   '
   ' MsgBox(Detect_Text_Encoding("C:\ANSI File.txt").ToString) ' Result: System.Text.SBCSCodePageEncoding
   ' MsgBox(Detect_Text_Encoding("C:\UTF8 File.txt").ToString) ' Result: System.Text.UTF8Encoding


   Public Function Detect_Text_Encoding(TextFile As String) As System.Text.Encoding

       Dim Bytes() As Byte = IO.File.ReadAllBytes(TextFile)

       Dim detectedEncoding As System.Text.Encoding = Nothing

       For Each info As System.Text.EncodingInfo In System.Text.Encoding.GetEncodings()

           Dim currentEncoding As System.Text.Encoding = info.GetEncoding()
           Dim preamble() As Byte = currentEncoding.GetPreamble()
           Dim match As Boolean = True

           If (preamble.Length > 0) And (preamble.Length <= Bytes.Length) Then

               For i As Integer = 0 To preamble.Length - 1

                   If preamble(i) <> Bytes(i) Then
                       match = False
                       Exit For
                   End If

               Next i

           Else

               match = False

           End If

           If match Then
               detectedEncoding = currentEncoding
               Exit For
           End If

       Next info

       If detectedEncoding Is Nothing Then
           Return System.Text.Encoding.Default
       Else
           Return detectedEncoding
       End If

   End Function

#End Region








Eleкtro

#301
Permitir la escritura de 1 solo caracter en un textbox y deshabilitar el menú contextual, tiene algunas diferencias de la propiedad "MaxLength", no pega el primer caracter de una palabra del clipboards si la longitud de la palabra es de 1 caracter (es un code un poco "custom", util para especificar delimitadores de texto de un solo caracter, o cosas parecidas)

Código (vbnet) [Seleccionar]
#Region " [TextBox] Allow only 1 Character "

   ' By Elektro H@cker


   ' TextBox [Enter]
   Private Sub TextBox_Enter(sender As Object, e As EventArgs) ' Handles TextBox1.MouseEnter

       ' Allign the character in the TextBox space
       ' If Not TextBox_Separator.TextAlign = HorizontalAlignment.Center Then TextBox_Separator.TextAlign = HorizontalAlignment.Center Then

       ' Disable Copy/Paste contextmenu by creating a new one
       If sender.ContextMenuStrip Is Nothing Then sender.ContextMenuStrip = New ContextMenuStrip

   End Sub

   ' TextBox [KeyPress]
   Private Sub TextBox_KeyPress(sender As Object, e As KeyPressEventArgs) ' Handles TextBox1.KeyPress

       Select Case sender.TextLength

           Case 0 ' TextLength = 0

               Select Case e.KeyChar

                   Case Chr(22) ' CTRL+V is pressed

                       ' If Clipboard contains 0 or 1 character then paste the character.
                       e.Handled = IIf(Clipboard.GetText.Length <= 1, False, True)
               
                   Case Else ' Other key is pressed
                       e.Handled = False ' Print the character.

               End Select ' e.KeyChar when TextLength = 0

           Case 1 ' TextLength = 1

               Select Case e.KeyChar

                   Case Convert.ToChar(Keys.Back) ' Backspace is pressed
                       e.Handled = False ' Delete the character

                   Case Chr(22) ' CTRL+V is pressed

                       Select Case sender.SelectionLength

                           Case 1 ' If 1 character is selected
                               ' If Clipboard contains 0 or 1 character then paste the character.
                               e.Handled = IIf(Clipboard.GetText.Length <= 1, False, True)

                           Case Else ' If any text is selected
                               e.Handled = True ' Don't paste the characters.

                       End Select

                   Case Else ' Other key is pressed
                       ' If any text is selected then don't print the character.
                       e.Handled = IIf(sender.SelectionLength = 1, False, True)

               End Select ' e.KeyChar when TextLength = 1

       End Select ' TextLength

   End Sub

   ' TextBox [TextChanged]
   Private Sub TextBox_TextChanged(sender As Object, e As EventArgs) ' Handles TextBox1.TextChanged

       ' // If NOT Text is empty then Save the character:
       '
       ' If Not String.IsNullOrEmpty(sender.text) _
       ' Then My.Settings.User_Character = Convert.ToChar(sender.text)

   End Sub

   ' TextBox [Leave]
   Private Sub TextBox_Leave(sender As Object, e As EventArgs) ' Handles TextBox1.Leave

       ' // If Text is empty then restore the last saved character:
       '
       ' If String.IsNullOrEmpty(sender.text) _
       ' Then sender.text = My.Settings.User_Character

   End Sub

#End Region








Eleкtro

Listar por el método Burbuja un Array de String o una Lista de String:

Código (vbnet) [Seleccionar]
#Region " BubbleSort Array "

    ' BubbleSort Array
    '
    ' Examples :
    '
    ' Dim MyArray As String() = {"10", "333", "2", "45"}
    ' For Each item In BubbleSort_Array(myarray) : MsgBox(item) : Next ' Result: {"2", "10", "45", "333"}

    Private Function BubbleSort_Array(list As String()) As String()

        Return list.Select(Function(s) New With { _
            Key .OrgStr = s, _
            Key .SortStr = System.Text.RegularExpressions.Regex.Replace( _
                           s, "(\d+)|(\D+)", _
                           Function(m) m.Value.PadLeft(list.Select(Function(y) y.Length).Max, _
                           If(Char.IsDigit(m.Value(0)), " "c, Char.MaxValue))) _
        }).OrderBy(Function(x) x.SortStr).Select(Function(x) x.OrgStr).ToArray

    End Function

#End Region


Código (vbnet) [Seleccionar]
#Region " BubbleSort IEnumerable(Of String) "


    ' BubbleSort IEnumerable(Of String)
    '
    ' Examples :
    '
    ' Dim MyIEnumerable As IEnumerable(Of String) = {"10", "333", "2", "45"}
    ' For Each item In BubbleSort_IEnumerable(MyIEnumerable) : MsgBox(item) : Next ' Result: {"2", "10", "45", "333"}

    Private Function BubbleSort_IEnumerable(list As IEnumerable(Of String)) As IEnumerable(Of String)

        Return list.Select(Function(s) New With { _
            Key .OrgStr = s, _
            Key .SortStr = System.Text.RegularExpressions.Regex.Replace( _
                           s, "(\d+)|(\D+)", _
                           Function(m) m.Value.PadLeft(list.Select(Function(y) y.Length).Max, _
                           If(Char.IsDigit(m.Value(0)), " "c, Char.MaxValue))) _
        }).OrderBy(Function(x) x.SortStr).Select(Function(x) x.OrgStr)

    End Function

#End Region


Código (vbnet) [Seleccionar]
#Region " BubbleSort List(Of String) "


    ' BubbleSort List(Of String)
    '
    ' Examples :
    '
    ' Dim MyList As New List(Of String) From {"10", "333", "2", "45"}
    ' For Each item In BubbleSort_List(MyList) : MsgBox(item) : Next ' Result: {"2", "10", "45", "333"}

    Private Function BubbleSort_List(list As List(Of String)) As List(Of String)

        Return list.Select(Function(s) New With { _
            Key .OrgStr = s, _
            Key .SortStr = System.Text.RegularExpressions.Regex.Replace( _
                           s, "(\d+)|(\D+)", _
                           Function(m) m.Value.PadLeft(list.Select(Function(x) x.Length).Max, _
                           If(Char.IsDigit(m.Value(0)), " "c, Char.MaxValue))) _
        }).OrderBy(Function(x) x.SortStr).Select(Function(x) x.OrgStr).ToList

    End Function

#End Region







Listar por el  método Burbuja una Lista de DirectoryInfo o de FileInfo especificando la propiedad que se evaluará (por el momento solo funciona con propiedades "TopLevel"):

Código (vbnet) [Seleccionar]
#Region " BubbleSort List(Of DirectoryInfo) "

    ' BubbleSort List(Of DirectoryInfo)
    '
    ' Examples :
    '
    ' Dim Folders As List(Of IO.DirectoryInfo) = IO.Directory.GetDirectories("C:\Windows", "*").Select(Function(p) New IO.DirectoryInfo(p)).ToList()
    '
    ' For Each folder In Bubble_Sort_List_DirectoryInfo(Folders, Function() New IO.DirectoryInfo("").Name)
    '     MsgBox(folder.Name)
    ' Next

    Private Shared Function Bubble_Sort_List_DirectoryInfo(list As List(Of IO.DirectoryInfo), _
                                                         exp As Linq.Expressions.Expression(Of Func(Of Object))) _
                                                         As List(Of IO.DirectoryInfo)

        Dim member As Linq.Expressions.MemberExpression = _
            If(TypeOf exp.Body Is Linq.Expressions.UnaryExpression, _
               DirectCast(DirectCast(exp.Body, Linq.Expressions.UnaryExpression).Operand, Linq.Expressions.MemberExpression), _
               DirectCast(exp.Body, Linq.Expressions.MemberExpression))

        Return list.Select(Function(s) New With { _
        Key .OrgStr = s, _
        Key .SortStr = System.Text.RegularExpressions.Regex.Replace( _
                       s.Name, "(\d+)|(\D+)", _
                       Function(m) m.Value.PadLeft( _
                                   list.Select(Function(folder) DirectCast(DirectCast(member.Member, System.Reflection.PropertyInfo) _
                                                                .GetValue(folder, Nothing), Object).ToString.Length).Max(), _
                                                                If(Char.IsDigit(m.Value(0)), " "c, Char.MaxValue))) _
        }).OrderBy(Function(x) x.SortStr).Select(Function(x) x.OrgStr).ToList

    End Function

#End Region


Código (vbnet) [Seleccionar]
#Region " BubbleSort List(Of FileInfo) "

    ' BubbleSort List(Of FileInfo)
    '
    ' Examples :
    '
    ' Dim Files As List(Of IO.FileInfo) = IO.Directory.GetFiles("C:\Windows", "*").Select(Function(p) New IO.FileInfo(p)).ToList()
    '
    ' For Each file In Bubble_Sort_List_FileInfo(Files, Function() New IO.FileInfo("").Name)
    '     MsgBox(file.Name)
    ' Next

    Private Shared Function Bubble_Sort_List_FileInfo(list As List(Of IO.FileInfo), _
                                                         exp As Linq.Expressions.Expression(Of Func(Of Object))) _
                                                         As List(Of IO.FileInfo)

        Dim member As Linq.Expressions.MemberExpression = _
            If(TypeOf exp.Body Is Linq.Expressions.UnaryExpression, _
               DirectCast(DirectCast(exp.Body, Linq.Expressions.UnaryExpression).Operand, Linq.Expressions.MemberExpression), _
               DirectCast(exp.Body, Linq.Expressions.MemberExpression))

        Return list.Select(Function(s) New With { _
        Key .OrgStr = s, _
        Key .SortStr = System.Text.RegularExpressions.Regex.Replace( _
                       s.Name, "(\d+)|(\D+)", _
                       Function(m) m.Value.PadLeft( _
                                   list.Select(Function(file) DirectCast(DirectCast(member.Member, System.Reflection.PropertyInfo) _
                                                                .GetValue(file, Nothing), Object).ToString.Length).Max(), _
                                                                If(Char.IsDigit(m.Value(0)), " "c, Char.MaxValue))) _
        }).OrderBy(Function(x) x.SortStr).Select(Function(x) x.OrgStr).ToList

    End Function

#End Region








Eleкtro

Varias maneras de Activar/Desactivar una serie de contorles:

Código (vbnet) [Seleccionar]
#Region " Disable Controls "

    ' [ Disable Controls ]
    '
    ' // By Elektro H@cker
    '
    ' Examples :
    '
    ' Disable_Controls(Button1)
    ' Disable_Controls({Button1, Button2})
    ' Disable_Controls(Of Button)(GroupBox1, False)
    ' Disable_Controls(Of Button)(GroupBox1.Controls, False)

    ' Disable Control(Control)
    Private Sub Disable_Control(ByVal [control] As Control)
        [control].Enabled = If([control].Enabled, False, True)
    End Sub

    ' Disable Controls({Control})
    Private Sub Disable_Controls(ByVal Controls() As Control)
        For Each [control] As Control In Controls
            [control].Enabled = If([control].Enabled, False, True)
        Next
    End Sub

    ' Disable Controls(Of Type)(Control)
    Public Sub Disable_Controls(Of T As Control)(ByVal Container As Control)
        For Each [control] As T In Container.Controls.OfType(Of T).Where(Function(ctrl) ctrl.Enabled)
            [control].Enabled = False
        Next
    End Sub

    ' Disable Controls(Of Type)(ControlCollection)
    Public Sub Disable_Controls(Of T As Control)(ByVal Collection As ControlCollection)
        For Each [control] As T In Collection.OfType(Of T).Where(Function(ctrl) ctrl.Enabled)
            [control].Enabled = False
        Next
    End Sub

#End Region


Código (vbnet) [Seleccionar]
#Region " Enable Controls "

    ' [ Enable Controls ]
    '
    ' // By Elektro H@cker
    '
    ' Examples :
    '
    ' Enable_Control(Button1)
    ' Enable_Controls({Button1, Button2})
    ' Enable_Controls(Of Button)(GroupBox1, False)
    ' Enable_Controls(Of Button)(GroupBox1.Controls, False)

    ' Enable Control(Control)
    Private Sub Enable_Control(ByVal [control] As Control)
        [control].Enabled = If(Not [control].Enabled, True, False)
    End Sub

    ' Enable Controls({Control})
    Private Sub Enable_Controls(ByVal Controls() As Control)
        For Each [control] As Control In Controls
            [control].Enabled = If(Not [control].Enabled, True, False)
        Next
    End Sub

    ' Enable Controls(Of Type)(Control)
    Public Sub Enable_Controls(Of T As Control)(ByVal Container As Control)
        For Each [control] As T In Container.Controls.OfType(Of T).Where(Function(ctrl) Not ctrl.Enabled)
            [control].Enabled = True
        Next
    End Sub

    ' Enable Controls(Of Type)(ControlCollection)
    Public Sub Enable_Controls(Of T As Control)(ByVal Collection As ControlCollection)
        For Each [control] As T In Collection.OfType(Of T).Where(Function(ctrl) Not ctrl.Enabled)
            [control].Enabled = True
        Next
    End Sub

#End Region








Eleкtro

#304
Una Class para manejar la aplicación mp3gain.

Sirve para aplicar una ganancia NO destructiva a archivos MP3.

http://mp3gain.sourceforge.net/

EDITO: Código mejorado.
Código (vbnet) [Seleccionar]
#Region " mp3gain Helper "



' [ mp3gain Helper ]
'
' // By Elektro H@cker
'
'
' Instructions:
'
' 1. Add the "mp3gain.exe" into the project.
'
'
' Examples :
'
' MsgBox(mp3gain.Is_Avaliable) ' Checks if mp3gain executable is avaliable.
'
' MsgBox(mp3gain.File_Has_MP3Gain_Tag("File.mp3")) ' Checks if file contains mp3gain APE tag
'
' mp3gain.Set_Gain("File.mp3", 95) ' Set the db Gain of file to 95 db (In a scale of "0/100" db)
' mp3gain.Set_Gain("File.mp3", 95, True) ' Set the db Gain of file to -95 db and preserve the datetime of file.
'
' mp3gain.Apply_Gain("File.mp3", +5) ' Apply a change of +5 db in the curent gain of file.
' mp3gain.Apply_Gain("File.mp3", -5) ' Apply a change of -5 db in the curent gain of file.
'
' mp3gain.Apply_Channel_Gain("File.mp3", mp3gain.Channels.Left, +10) ' Apply a change of +10 db in the curent Left channel gain of file.
' mp3gain.Apply_Channel_Gain("File.mp3", mp3gain.Channels.Right, -10) ' Apply a change of -10 db in the curent Right channel gain of file.
'
' mp3gain.Undo_Gain("File.mp3") ' Undo all MP3Gain db changes made in file.
'
'
' ------
' EVENTS
' ------
' Public WithEvents mp3gain As New mp3gain
'
' Sub mp3gain_Progress(Progress As Integer, e As EventArgs) Handles mp3gain.PercentDone
'     ProgressBar1.Maximum = 100
'     ProgressBar1.Value = Progress
' End Sub
'
' Sub mp3gain_Exited(Message As String, e As EventArgs) Handles mp3gain.Exited
'     ProgressBar1.Value = 0
'     MessageBox.Show(Message)
' End Sub



Public Class mp3gain

#Region " CommandLine parametter legend "

    ' MP3Gain Parametter Legend:
    '
    ' /c   - Ignore clipping warning when applying gain.
    ' /d   - Set global gain.
    ' /e   - Skip Album analysis, even if multiple files listed.
    ' /g   - apply gain
    ' /p   - Preserve original file timestamp.
    ' /r   - apply Track gain automatically (all files set to equal loudness)
    ' /t   - Writes modified data to temp file, then deletes original instead of modifying bytes in original file.
    ' /u   - Undo changes made (based on stored tag info).
    ' /s c - Check stored tag info.

#End Region

#Region " Variables "

    ' <summary>
    ' Gets or sets the mp3gain.exe executable path.
    ' </summary>
    Public Shared mp3gain_Location As String = "c:\mp3gain.exe"

    ' Stores the MP3Gain process ErrorOutput.
    Private Shared ErrorOutput As String = String.Empty

    ' Stores the MP3Gain process StandardOutput.
    Private Shared StandardOutput As String = String.Empty ' Is not needed

    ' Sets a Flag to know if file has MP3Gain APE tag.
    Private Shared HasTag As Boolean = False

#End Region

#Region " Enumerations "

    Enum Channels As Short
        Left = 0  ' /l 0
        Right = 1 ' /l 1
    End Enum

#End Region

#Region " Events "

    ' <summary>
    ' Event raised when process progress changes.
    ' </summary>
    Public Shared Event PercentDone As EventHandler(Of PercentDoneEventArgs)
    Public Class PercentDoneEventArgs : Inherits EventArgs
        Public Property Progress As Integer
    End Class

    ' <summary>
    ' Event raised when MP3Gain process has exited.
    ' </summary>
    Public Shared Event Exited As EventHandler(Of ExitedEventArgs)
    Public Class ExitedEventArgs : Inherits EventArgs
        Public Property Message As String
    End Class

#End Region

#Region " Processes Info "

    Private Shared Process_TagCheck As New Process() With { _
    .StartInfo = New ProcessStartInfo With { _
                .CreateNoWindow = True, _
                .UseShellExecute = False, _
                .RedirectStandardError = False, _
                .RedirectStandardOutput = True _
    }}

    Private Shared Process_For_Tag As New Process() With { _
    .StartInfo = New ProcessStartInfo With { _
                .CreateNoWindow = True, _
                .UseShellExecute = False, _
                .RedirectStandardError = False, _
                .RedirectStandardOutput = True _
    }}

    Private Shared Process_For_NonTag As New Process() With { _
    .StartInfo = New ProcessStartInfo With { _
                .CreateNoWindow = True, _
                .UseShellExecute = False, _
                .RedirectStandardError = True, _
                .RedirectStandardOutput = True _
    }}

#End Region

#Region " Miscellaneous functions "

    ' <summary>
    ' Checks if mp3gain.exe process is avaliable.
    ' </summary>
    Public Shared Function Is_Avaliable() As Boolean
        Return IO.File.Exists(mp3gain_Location)
    End Function

    ' Checks if a file exist.
    Private Shared Sub CheckFileExists(ByVal File As String)

        If Not IO.File.Exists(File) Then
            ' Throw New Exception("File doesn't exist: " & File)
            MessageBox.Show("File doesn't exist: " & File, "MP3Gain", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End If

    End Sub

#End Region

#Region " Gain Procedures "

    ' <summary>
    ' Checks if mp3gain APE tag exists in file.
    ' </summary>
    Public Shared Function File_Has_MP3Gain_Tag(ByVal MP3_File As String) As Boolean

        CheckFileExists(MP3_File)

        Process_TagCheck.StartInfo.FileName = mp3gain_Location
        Process_TagCheck.StartInfo.Arguments = String.Format("/s c ""{0}""", MP3_File)
        Process_TagCheck.Start()
        Process_TagCheck.WaitForExit()

        Return Process_TagCheck.StandardOutput.ReadToEnd.Trim.Split(Environment.NewLine).Count - 1

        ' Process_TagCheck.Close()

    End Function

    ' <summary>
    ' Set global db Gain in file.
    ' </summary>
    Public Shared Sub Set_Gain(ByVal MP3_File As String, _
                               ByVal Gain As Integer, _
                               Optional ByVal Preserve_Datestamp As Boolean = True)

        Run_MP3Gain(MP3_File, String.Format("/c /e /r /t {1} /d {2} ""{0}""", _
                                            MP3_File, _
                                            If(Preserve_Datestamp, "/p", ""), _
                                            If(Gain < 0, Gain + 89.0, Gain - 89.0)))

    End Sub

    ' <summary>
    ' Apply db Gain change in file.
    ' </summary>
    Public Shared Sub Apply_Gain(ByVal MP3_File As String, _
                                 ByVal Gain As Integer, _
                                 Optional ByVal Preserve_Datestamp As Boolean = True)

        Run_MP3Gain(MP3_File, String.Format("/c /e /r /t {1} /g {2} ""{0}""", _
                                            MP3_File, _
                                            If(Preserve_Datestamp, "/p", ""), _
                                            Gain))

    End Sub

    ' <summary>
    ' Apply db Gain change of desired channel in file.
    ' Only works for Stereo MP3 files.
    ' </summary>
    Public Shared Sub Apply_Channel_Gain(ByVal MP3_File As String, _
                                         ByVal Channel As Channels, _
                                         ByVal Gain As Integer, _
                                         Optional ByVal Preserve_Datestamp As Boolean = True)

        Run_MP3Gain(MP3_File, String.Format("/c /e /r /l {2} {3} ""{0}""", _
                                            MP3_File, _
                                            If(Preserve_Datestamp, "/p", ""), _
                                            If(Channel = Channels.Left, 0, 1), _
                                            Gain))

    End Sub

    ' <summary>
    ' Undo all MP3Gain db changes made in file (based on stored tag info).
    ' </summary>
    Public Shared Sub Undo_Gain(ByVal MP3_File As String, _
                                Optional ByVal Preserve_Datestamp As Boolean = True)

        Run_MP3Gain(MP3_File, String.Format("/c /t {1} /u ""{0}""", _
                                            MP3_File, _
                                            If(Preserve_Datestamp, "/p", "")))

    End Sub

#End Region

#Region " Run MP3Gain Procedures "

    Private Shared Sub Run_MP3Gain(ByVal MP3_File As String, ByVal Parametters As String)

        CheckFileExists(MP3_File)

        HasTag = File_Has_MP3Gain_Tag(MP3_File)

        Process_For_Tag.StartInfo.FileName = mp3gain_Location
        Process_For_Tag.StartInfo.Arguments = Parametters

        Process_For_NonTag.StartInfo.FileName = mp3gain_Location
        Process_For_NonTag.StartInfo.Arguments = Parametters

        If HasTag Then
            Run_MP3Gain_For_Tag()
        Else
            Run_MP3Gain_For_NonTag()
        End If

    End Sub

    Private Shared Sub Run_MP3Gain_For_Tag()

        Process_For_Tag.Start()
        Process_For_Tag.WaitForExit()

        RaiseEvent Exited(Process_For_Tag.StandardOutput.ReadToEnd.Trim.Split(Environment.NewLine).LastOrDefault, Nothing)

        StandardOutput = Nothing
        ' Process_For_Tag.Close()

    End Sub

    Private Shared Sub Run_MP3Gain_For_NonTag()

        Process_For_NonTag.Start()

        While Not Process_For_NonTag.HasExited

            Try

                ErrorOutput = Process_For_NonTag.StandardError.ReadLine.Trim.Split("%").First
                If CInt(ErrorOutput) < 101 Then
                    RaiseEvent PercentDone(ErrorOutput, Nothing)
                End If

            Catch : End Try

        End While

        StandardOutput = Process_For_NonTag.StandardOutput.ReadToEnd.Trim.Split(Environment.NewLine).Last

        RaiseEvent Exited(StandardOutput, Nothing)

        ErrorOutput = Nothing
        StandardOutput = Nothing
        ' Process_For_Tag.Close()

    End Sub

#End Region

End Class

#End Region








Eleкtro

Un ayudante para manejar la librería TabLig Sharp: https://github.com/mono/taglib-sharp

La librería sirve para editar los metadatos de archivos de música, entre otros formatos como imágenes png, etc...

Mi Class está pensada para usarse con archivos MP3.

Código (vbnet) [Seleccionar]
#Region " TagLib Sharp Helper "


' [ TagLib Sharp Helper ]
'
' // By Elektro H@cker
'
'
' Instructions:
' 1. Add a reference to "taglib-sharp.dll" into the project.
'
'
' Examples:
'
' MsgBox(TagLibSharp.FileIsCorrupt("C:\File.mp3")) ' Result: True or False
' MsgBox(TagLibSharp.FileIsWriteable("C:\File.mp3")) ' Result: True or False
' MsgBox(TagLibSharp.Get_Title("C:\File.mp3"))
' MsgBox(TagLibSharp.Get_Artist("C:\File.mp3"))
' MsgBox(TagLibSharp.Get_Album("C:\File.mp3"))
' MsgBox(TagLibSharp.Get_Genre("C:\File.mp3"))
' MsgBox(TagLibSharp.Get_Year("C:\File.mp3"))
' MsgBox(TagLibSharp.Get_Basic_TagInfo("C:\File.mp3"))
' TagLibSharp.RemoveTag("C:\File.mp3", TagLib.TagTypes.Id3v1 Or TagLib.TagTypes.Id3v2) ' Removes ID3v1 + ID3v2 Tags
' TagLibSharp.Set_Tag_Fields("C:\Test.mp3", Sub(x) x.Tag.Title = "Title Test"})
' TagLibSharp.Set_Tag_Fields("C:\Test.mp3", {Sub(x) x.Tag.Title = "Title Test", Sub(x) x.Tag.Performers = {"Artist Test"}})


Public Class TagLibSharp

    ''' <summary>
    ''' Stores the Taglib object.
    ''' </summary>
    Private Shared TagFile As TagLib.File = Nothing

    ''' <summary>
    ''' Checks if file is possibly corrupted.
    ''' </summary>
    Public Shared Function FileIsCorrupt(ByVal File As String) As Boolean

        Try
            Return TagLib.File.Create(File).PossiblyCorrupt

        Catch ex As Exception
            Throw New Exception(ex.Message)
            Return True

        Finally
            If TagFile IsNot Nothing Then TagFile.Dispose()

        End Try

    End Function

''' <summary>
''' Checks if file can be written.
''' </summary>
Public Shared Function FileIsWriteable(ByVal File As String) As Boolean

    Try
        Return TagLib.File.Create(File).Writeable

    Catch ex As Exception
        Throw New Exception(ex.Message)
        Return True

    Finally
        If TagFile IsNot Nothing Then TagFile.Dispose()

    End Try

End Function

''' <summary>
''' Get TagTypes of file.
''' </summary>
Public Shared Function Get_Tags(ByVal File As String) As String

    Try
        Return TagLib.File.Create(File).TagTypes.ToString

    Catch ex As Exception
        Throw New Exception(ex.Message)
        Return String.Empty

    Finally
        If TagFile IsNot Nothing Then TagFile.Dispose()

    End Try

End Function

''' <summary>
''' Remove a entire Tag from file.
''' </summary>
Public Shared Sub RemoveTag(ByVal File As String, ByVal TagTypes As TagLib.TagTypes)

    Try
        TagFile = TagLib.File.Create(File)
    Catch ex As Exception
        Throw New Exception(ex.Message)
        Exit Sub
    End Try

    Try

        If Not TagFile.PossiblyCorrupt _
        AndAlso TagFile.Writeable Then

            TagFile.RemoveTags(TagTypes)
            TagFile.Save()

        End If

    Catch ex As Exception
        Throw New Exception(ex.Message)

    Finally
        If TagFile IsNot Nothing Then TagFile.Dispose()

    End Try

End Sub

''' <summary>
''' Gets the Title tag field of file.
''' </summary>
Public Shared Function Get_Title(ByVal File As String) As String

    Try
        Return TagLib.File.Create(File).Tag.Title

    Catch ex As Exception
        Throw New Exception(ex.Message)
        Return String.Empty

    Finally
        If TagFile IsNot Nothing Then TagFile.Dispose()

    End Try

End Function

''' <summary>
''' Gets the Artist tag field of file.
''' </summary>
Public Shared Function Get_Artist(ByVal File As String) As String

    Try
        Return TagLib.File.Create(File).Tag.Performers(0)

    Catch ex As Exception
        Throw New Exception(ex.Message)
        Return String.Empty

    Finally
        If TagFile IsNot Nothing Then TagFile.Dispose()

    End Try

End Function

''' <summary>
''' Gets the Album tag field of file.
''' </summary>
Public Shared Function Get_Album(ByVal File As String) As String

    Try
        Return TagLib.File.Create(File).Tag.Album

    Catch ex As Exception
        Throw New Exception(ex.Message)
        Return String.Empty

    Finally
        If TagFile IsNot Nothing Then TagFile.Dispose()

    End Try

End Function

''' <summary>
''' Gets the Genre tag field of file.
''' </summary>
Public Shared Function Get_Genre(ByVal File As String) As String

    Try
        Return TagLib.File.Create(File).Tag.Genres(0)

    Catch ex As Exception
        Throw New Exception(ex.Message)
        Return String.Empty

    Finally
        If TagFile IsNot Nothing Then TagFile.Dispose()

    End Try

End Function

''' <summary>
''' Gets the Year tag field of file.
''' </summary>
Public Shared Function Get_Year(ByVal File As String) As String

    Try
        Return TagLib.File.Create(File).Tag.Year

    Catch ex As Exception
        Throw New Exception(ex.Message)
        Return String.Empty

    Finally
        If TagFile IsNot Nothing Then TagFile.Dispose()

    End Try

End Function

''' <summary>
''' Gets the basic tag fields of file.
''' </summary>
Public Shared Function Get_Basic_TagInfo(ByVal File As String) As String

    Try
        TagFile = TagLib.File.Create(File)

        Return String.Format("Title: {1}{0}Artist: {2}{0}Album: {3}{0}Genre: {4}{0}Year: {5}", Environment.NewLine, _
                             TagFile.Tag.Title, _
                             TagFile.Tag.Performers(0), _
                             TagFile.Tag.Album, _
                             TagFile.Tag.Genres(0), _
                             TagFile.Tag.Year)

    Catch ex As Exception
        Throw New Exception(ex.Message)
        Return String.Empty

    Finally
        If TagFile IsNot Nothing Then TagFile.Dispose()

    End Try

End Function

''' <summary>
''' Sets a Tag field.
''' </summary>
Public Shared Sub Set_Tag_Fields(ByVal File As String, _
                                   ByVal FieldSetter As Action(Of TagLib.File))

    Try
        TagFile = TagLib.File.Create(File)
    Catch ex As Exception
        Throw New Exception(ex.Message)
        Exit Sub
    End Try

    Try

        If Not TagFile.PossiblyCorrupt _
        AndAlso TagFile.Writeable Then

            FieldSetter(TagFile)
            TagFile.Save()

        End If

    Catch ex As Exception
        Throw New Exception(ex.Message)

    Finally
        If TagFile IsNot Nothing Then TagFile.Dispose()

    End Try

End Sub

''' <summary>
''' Sets multiple Tag fields.
''' </summary>
Public Shared Sub Set_Tag_Fields(ByVal File As String, _
                                   ByVal FieldSetter() As Action(Of TagLib.File))

    Try
        TagFile = TagLib.File.Create(File)
    Catch ex As Exception
        Throw New Exception(ex.Message)
        Exit Sub
    End Try

    Try

        If Not TagFile.PossiblyCorrupt _
        AndAlso TagFile.Writeable Then

            For Each Field In FieldSetter
                Field(TagFile)
            Next

            TagFile.Save()

        End If

    Catch ex As Exception
        Throw New Exception(ex.Message)

    Finally
        If TagFile IsNot Nothing Then TagFile.Dispose()

    End Try

End Sub

End Class

#End Region








Eleкtro

#306
Un ayudante de la librería UltraId3Lib: http://home.fuse.net/honnert/UltraID3Lib/UltraID3Lib0968.zip

La diferencia entre esta librería y TagLib Sharp es que UltraID3Lib trabaja sólamente metadatos de tipo ID3v1 e ID3v2 (y las variantes de ID3v2, y los Covers)

Esta librería está optimizada para trabajar archivos MP3, de hecho sólamente trabaja archivos mp3, además hice un pequeño test de velocidad y estos fueron los resultados:

Citar                                                                                               TagLib Sharp        UltraId3Lib
Tiempo transcurrido para eliminar los tags ID3v1 + ID3v2 de 1.000 archivos mp3 (5,2 GB)       05:40 minutos       03:10 minutos

Ahora... si tuviera que elegir entre la lógica interna que usa cada librería, lo cierto es que no sabría por cual decidirme, por eso hice un ayudante para las dos librerías xD.

EDITO: He extendido la Class para manejar las carátulas de los mp3.

EDITO: He vuelto ha extender la Class para exprimir un poco más la librería.

Código (vbnet) [Seleccionar]

#Region " UltraID3Lib "



' [ UltraID3Lib Helper ]
'
' // By Elektro H@cker
'
'
' Instructions:
' 1. Add a reference to "UltraID3Lib.dll" into the project.
'
'
' Examples:
'
' MsgBox(UltraID3Lib.FileIsCorrupt("C:\File.mp3")) ' Result: True or False
' MsgBox(UltraID3Lib.ID3v1_Exist("C:\File.mp3"))   ' Result: True or False
' MsgBox(UltraID3Lib.ID3v2_Exist("C:\File.mp3"))   ' Result: True or False
' MsgBox(UltraID3Lib.IsVBR("C:\File.mp3"))         ' Result: True or False
' MsgBox(UltraID3Lib.Get_Metadata_Errors("C:\File.mp3"))
' MsgBox(UltraID3Lib.Get_Metadata_Warnings("C:\File.mp3"))
'
' MsgBox(UltraID3Lib.Get_ID3_Tags("C:\File.mp3"))
' MsgBox(UltraID3Lib.Get_Title("C:\File.mp3"))
' MsgBox(UltraID3Lib.Get_Artist("C:\File.mp3"))
' MsgBox(UltraID3Lib.Get_Album("C:\File.mp3"))
' MsgBox(UltraID3Lib.Get_Genre("C:\File.mp3"))
' MsgBox(UltraID3Lib.Get_Year("C:\File.mp3"))
' MsgBox(UltraID3Lib.Get_Basic_Tag_Fields("C:\File.mp3"))
'
' UltraID3Lib.Remove_ID3v1_Tag("C:\File.mp3") ' Removes ID3v1 Tag
' UltraID3Lib.Remove_ID3v2_Tag("C:\File.mp3") ' Removes ID3v2 Tag
' UltraID3Lib.Remove_ID3v1_ID3v2_Tags("C:\File.mp3") ' Removes ID3v1 + ID3v2 Tags
'
' UltraID3Lib.Set_Tag_Field("C:\File.mp3", Sub(x) x.ID3v2Tag.Title = "Title Test")
' UltraID3Lib.Set_Tag_Fields("C:\File.mp3", {Sub(x) x.ID3v2Tag.Title = "Title Test", Sub(x) x.ID3v2Tag.Artist = "Artist Test"})
'
' UltraID3Lib.Set_Main_Cover("C:\File.mp3", "C:\Image.jpg")
' UltraID3Lib.Add_Cover("C:\File.mp3", "C:\Image.jpg")
' UltraID3Lib.Delete_Covers("C:\File.mp3")
' PictureBox1.BackgroundImage = UltraID3Lib.Get_Main_Cover("C:\File.mp3")
'
' For Each Genre As String In UltraID3Lib.Get_Generic_ID3_Genres() : MsgBox(Genre) : Next
'
' MsgBox(UltraID3Lib.Get_Bitrate("C:\File.mp3")) ' Result: 320
' MsgBox(UltraID3Lib.Get_Duration("C:\File.mp3")) ' Result: 00:00:00:000
' MsgBox(UltraID3Lib.Get_Frequency("C:\File.mp3")) ' Result: 44100
' MsgBox(UltraID3Lib.Get_Channels("C:\File.mp3")) ' Result: JointStereo
' MsgBox(UltraID3Lib.Get_Layer("C:\File.mp3")) ' Result: MPEGLayer3
' MsgBox(UltraID3Lib.Get_Filesize("C:\File.mp3")) ' Result: 6533677



Imports HundredMilesSoftware.UltraID3Lib

Public Class UltraID3Lib

    ''' <summary>
    ''' Stores the UltraID3Lib object.
    ''' </summary>
    Private Shared [UltraID3] As New UltraID3

    ' ''' <summary>
    ' ''' Stores the Picture things.
    ' ''' </summary>
    ' Private Shared CurrentPictureFrame As ID3v2PictureFrame ' Not used in this Class
    ' Private Shared PictureTypes As ArrayList ' Not used in this Class
    ' Private Shared PictureFrames As ID3FrameCollection ' Not used in this Class
    ' Private Shared PictureIndex As Integer ' Not used in this Class

    ''' <summary>
    ''' Checks if file is possibly corrupt.
    ''' </summary>
    Public Shared Function FileIsCorrupt(ByVal File As String) As Boolean

        Try
            [UltraID3].Read(File)
            Return Convert.ToBoolean( _
                       [UltraID3].GetExceptions(ID3ExceptionLevels.Error).Length _
                     + [UltraID3].GetExceptions(ID3ExceptionLevels.Warning).Length)

        Catch ex As Exception
            Throw New Exception(ex.Message)
        End Try

    End Function

    ''' <summary>
    ''' Checks for errors inside file metadata.
    ''' </summary>
    Public Shared Function Get_Metadata_Errors(ByVal File As String) As String

        Try
            [UltraID3].Read(File)
            Return String.Join(Environment.NewLine, _
                               [UltraID3].GetExceptions(ID3ExceptionLevels.Error) _
                               .Select(Function(ex) ex.Message))

        Catch ex As Exception
            Throw New Exception(ex.Message)
        End Try

    End Function

    ''' <summary>
    ''' Checks for warnings inside file metadata.
    ''' </summary>
    Public Shared Function Get_Metadata_Warnings(ByVal File As String) As String

        Try
            [UltraID3].Read(File)
            Return String.Join(Environment.NewLine, _
                               [UltraID3].GetExceptions(ID3ExceptionLevels.Warning) _
                               .Select(Function(ex) ex.Message))

        Catch ex As Exception
            Throw New Exception(ex.Message)
        End Try

    End Function

    ''' <summary>
    ''' Checks if ID3v1 exists in file.
    ''' </summary>
    Public Shared Function ID3v1_Exist(ByVal File As String) As Boolean

        Try
            [UltraID3].Read(File)
            Return [UltraID3].ID3v1Tag.ExistsInFile
        Catch ex As Exception
            Throw New Exception(ex.Message)
        End Try

    End Function

    ''' <summary>
    ''' Checks if ID3v2 exists in file.
    ''' </summary>
    Public Shared Function ID3v2_Exist(ByVal File As String) As Boolean

        Try
            [UltraID3].Read(File)
            Return [UltraID3].ID3v2Tag.ExistsInFile
        Catch ex As Exception
            Throw New Exception(ex.Message)
        End Try

    End Function

    ''' <summary>
    ''' Gets ID3 TagTypes of file.
    ''' </summary>
    Public Shared Function Get_ID3_Tags(ByVal File As String) As String

        Try
            [UltraID3].Read(File)

            Return String.Format("{0}{1}", _
                                 If([UltraID3].ID3v1Tag.ExistsInFile, "ID3v1, ", ""), _
                                 If([UltraID3].ID3v2Tag.ExistsInFile, " ID3v2", "")).Trim

        Catch ex As Exception
            Throw New Exception(ex.Message)

        End Try

    End Function

    ''' <summary>
    ''' Removes entire ID3v1 Tag from file.
    ''' </summary>
    Public Shared Sub Remove_ID3v1_Tag(ByVal File As String)

        Try
            [UltraID3].Read(File)
            [UltraID3].ID3v1Tag.Clear()
            [UltraID3].Write()

        Catch ex As Exception
            Throw New Exception(ex.Message)

        End Try

    End Sub

    ''' <summary>
    ''' Removes entire ID3v2 Tag from file.
    ''' </summary>
    Public Shared Sub Remove_ID3v2_Tag(ByVal File As String)

        Try
            [UltraID3].Read(File)
            [UltraID3].ID3v2Tag.Clear()
            [UltraID3].Write()

        Catch ex As Exception
            Throw New Exception(ex.Message)

        End Try

    End Sub

    ''' <summary>
    ''' Removes entire ID3v1 + ID3v2 Tags from file.
    ''' </summary>
    Public Shared Sub Remove_ID3v1_ID3v2_Tags(ByVal File As String)

        Try
            [UltraID3].Read(File)
            [UltraID3].ID3v1Tag.Clear()
            [UltraID3].ID3v2Tag.Clear()
            [UltraID3].Write()

        Catch ex As Exception
            Throw New Exception(ex.Message)

        End Try

    End Sub

    ''' <summary>
    ''' Gets the Title tag field of file.
    ''' </summary>
    Public Shared Function Get_Title(ByVal File As String) As String

        Try
            [UltraID3].Read(File)
            Return [UltraID3].Title

        Catch ex As Exception
            Throw New Exception(ex.Message)

        End Try

    End Function

    ''' <summary>
    ''' Gets the Artist tag field of file.
    ''' </summary>
    Public Shared Function Get_Artist(ByVal File As String) As String

        Try
            [UltraID3].Read(File)
            Return [UltraID3].Artist

        Catch ex As Exception
            Throw New Exception(ex.Message)

        End Try

    End Function

    ''' <summary>
    ''' Gets the Album tag field of file.
    ''' </summary>
    Public Shared Function Get_Album(ByVal File As String) As String

        Try
            [UltraID3].Read(File)
            Return [UltraID3].Album

        Catch ex As Exception
            Throw New Exception(ex.Message)

        End Try

    End Function

    ''' <summary>
    ''' Gets the Genre tag field of file.
    ''' </summary>
    Public Shared Function Get_Genre(ByVal File As String) As String

        Try
            [UltraID3].Read(File)
            Return [UltraID3].Genre

        Catch ex As Exception
            Throw New Exception(ex.Message)

        End Try

    End Function

    ''' <summary>
    ''' Gets the Year tag field of file.
    ''' </summary>
    Public Shared Function Get_Year(ByVal File As String) As String

        Try
            [UltraID3].Read(File)
            Return [UltraID3].Year

        Catch ex As Exception
            Throw New Exception(ex.Message)

        End Try

    End Function

    ''' <summary>
    ''' Gets the basic tag fields of file.
    ''' </summary>
    Public Shared Function Get_Basic_Tag_Fields(ByVal File As String) As String

        Try
            [UltraID3].Read(File)

            Return String.Format("Title: {1}{0}Artist: {2}{0}Album: {3}{0}Genre: {4}{0}Year: {5}", Environment.NewLine, _
                                 [UltraID3].Title, _
                                 [UltraID3].Artist, _
                                 [UltraID3].Album, _
                                 [UltraID3].Genre, _
                                 [UltraID3].Year)

        Catch ex As Exception
            Throw New Exception(ex.Message)
            Return String.Empty

        End Try

    End Function

    ''' <summary>
    ''' Sets a Tag field.
    ''' </summary>
    Public Shared Sub Set_Tag_Field(ByVal File As String, _
                                    ByVal FieldSetter As Action(Of UltraID3))

        Try
            [UltraID3].Read(File)
            FieldSetter([UltraID3])
            [UltraID3].Write()

        Catch ex As Exception
            Throw New Exception(ex.Message)

        End Try

    End Sub

    ''' <summary>
    ''' Sets multiple Tag fields.
    ''' </summary>
    Public Shared Sub Set_Tag_Fields(ByVal File As String, _
                                     ByVal FieldSetter() As Action(Of UltraID3))


        Try
            [UltraID3].Read(File)

            For Each Field As Action(Of UltraID3) In FieldSetter
                Field([UltraID3])
            Next

            [UltraID3].Write()

        Catch ex As Exception
            Throw New Exception(ex.Message)

        End Try

    End Sub

    ''' <summary>
    ''' Sets Main Picture Cover.
    ''' </summary>
    Public Shared Sub Set_Main_Cover(ByVal File As String, _
                            ByVal Picture As String)

        Try
            [UltraID3].Read(File)
            [UltraID3].ID3v2Tag.Frames.Add( _
                       New ID3v23PictureFrame(New Bitmap(Picture), PictureTypes.CoverFront, String.Empty, TextEncodingTypes.Unicode))

            [UltraID3].Write()

        Catch ex As Exception
            Throw New Exception(ex.Message)

        End Try

    End Sub

    ''' <summary>
    ''' Adds a Picture Cover.
    ''' </summary>
    Public Shared Sub Add_Cover(ByVal File As String, _
                                ByVal Picture As String)

        Try
            [UltraID3].Read(File)
            [UltraID3].ID3v2Tag.Frames.Add( _
                       New ID3v23PictureFrame(New Bitmap(Picture), PictureTypes.Other, String.Empty, TextEncodingTypes.Unicode))
            [UltraID3].Write()

        Catch ex As Exception
            Throw New Exception(ex.Message)

        End Try

    End Sub

    ''' <summary>
    ''' Deletes all Picture Covers.
    ''' </summary>
    Public Shared Sub Delete_Covers(ByVal File As String)

        Try
            [UltraID3].Read(File)

            [UltraID3].ID3v2Tag.Frames.Remove( _
                       [UltraID3].ID3v2Tag.Frames.GetFrames(MultipleInstanceID3v2FrameTypes.ID3v22Picture))

            [UltraID3].ID3v2Tag.Frames.Remove( _
                       [UltraID3].ID3v2Tag.Frames.GetFrames(MultipleInstanceID3v2FrameTypes.ID3v23Picture))

            [UltraID3].Write()

        Catch ex As Exception
            Throw New Exception(ex.Message)

        End Try

    End Sub

    ''' <summary>
    ''' Gets Main Picture Cover.
    ''' </summary>
    Public Shared Function Get_Main_Cover(ByVal File As String) As Bitmap

        Try
            [UltraID3].Read(File)

            If [UltraID3].ID3v2Tag.Frames.GetFrame(MultipleInstanceID3v2FrameTypes.ID3v23Picture, False) IsNot Nothing Then
                Return DirectCast( _
                       [UltraID3].ID3v2Tag.Frames.GetFrame(MultipleInstanceID3v2FrameTypes.ID3v23Picture, False),  _
                       ID3v2PictureFrame).Picture
            End If

            If [UltraID3].ID3v2Tag.Frames.GetFrame(MultipleInstanceID3v2FrameTypes.ID3v22Picture, False) IsNot Nothing Then
                Return DirectCast( _
                       [UltraID3].ID3v2Tag.Frames.GetFrame(MultipleInstanceID3v2FrameTypes.ID3v22Picture, False),  _
                       ID3v2PictureFrame).Picture
            End If

            Return Nothing

        Catch ex As Exception
            Throw New Exception(ex.Message)

        End Try

    End Function

    ''' <summary>
    ''' Gets the generic ID3 genre names.
    ''' </summary>
    Public Shared Function Get_Generic_ID3_Genres() As String()
        Return UltraID3.GenreInfos.Cast(Of GenreInfo).Select(Function(Genre) Genre.Name).ToArray
    End Function

    ''' <summary>
    ''' Gets the Audio Bitrate.
    ''' </summary>
    Public Shared Function Get_Bitrate(ByVal File As String) As Short

        Try
            [UltraID3].Read(File)
            Return [UltraID3].FirstMPEGFrameInfo.Bitrate

        Catch ex As Exception
            Throw New Exception(ex.Message)

        End Try

    End Function

    ''' <summary>
    ''' Gets the Audio Duration.
    ''' </summary>
    Public Shared Function Get_Duration(ByVal File As String) As String

        Try
            [UltraID3].Read(File)
            Return String.Format("{0:00}:{1:00}:{2:00}:{3:000}", _
                                  [UltraID3].FirstMPEGFrameInfo.Duration.Hours, _
                                  [UltraID3].FirstMPEGFrameInfo.Duration.Minutes, _
                                  [UltraID3].FirstMPEGFrameInfo.Duration.Seconds, _
                                  [UltraID3].FirstMPEGFrameInfo.Duration.Milliseconds)

        Catch ex As Exception
            Throw New Exception(ex.Message)

        End Try

    End Function

    ''' <summary>
    ''' Gets the Audio Frequency.
    ''' </summary>
    Public Shared Function Get_Frequency(ByVal File As String) As Integer

        Try
            [UltraID3].Read(File)
            Return [UltraID3].FirstMPEGFrameInfo.Frequency

        Catch ex As Exception
            Throw New Exception(ex.Message)

        End Try

    End Function

    ''' <summary>
    ''' Gets the Audio MPEG Layer.
    ''' </summary>
    Public Shared Function Get_Layer(ByVal File As String) As String

        Try
            [UltraID3].Read(File)
            Return [UltraID3].FirstMPEGFrameInfo.Layer.ToString

        Catch ex As Exception
            Throw New Exception(ex.Message)

        End Try

    End Function

    ''' <summary>
    ''' Gets the Audio Channel mode.
    ''' </summary>
    Public Shared Function Get_Channels(ByVal File As String) As String

        Try
            [UltraID3].Read(File)
            Return [UltraID3].FirstMPEGFrameInfo.Mode.ToString

        Catch ex As Exception
            Throw New Exception(ex.Message)

        End Try

    End Function

    ''' <summary>
    ''' Gets the File Size.
    ''' </summary>
    Public Shared Function Get_Filesize(ByVal File As String) As Long

        Try
            [UltraID3].Read(File)
            Return [UltraID3].Size

        Catch ex As Exception
            Throw New Exception(ex.Message)

        End Try

    End Function

    ''' <summary>
    ''' Checks if VBR header is present in file.
    ''' </summary>
    Public Shared Function IsVBR(ByVal File As String) As Boolean

        Try
            [UltraID3].Read(File)
            Return [UltraID3].FirstMPEGFrameInfo.VBRInfo.WasFound

        Catch ex As Exception
            Throw New Exception(ex.Message)

        End Try

    End Function

End Class

#End Region








Eleкtro

Un custom MessageBox que se puede alinear en el centro del formulario y además se puede personalizar la fuente de texto usada.

Modo de empleo:
Código (vbnet) [Seleccionar]
        Using New CustomMessageBox(Me, New Font(New FontFamily("Lucida Console"), Font.SizeInPoints, FontStyle.Bold))
            MessageBox.Show("Test Text", "Test Title", MessageBoxButtons.OK)
        End Using



Código (vbnet) [Seleccionar]
Imports System.Drawing
Imports System.Runtime.InteropServices
Imports System.Text
Imports System.Windows.Forms

Class CustomMessageBox : Implements IDisposable

    Private mTries As Integer = 0
    Private mOwner As Form
    Private mFont As Font

    ' P/Invoke declarations
    Private Const WM_SETFONT As Integer = &H30
    Private Const WM_GETFONT As Integer = &H31

    Private Delegate Function EnumThreadWndProc(hWnd As IntPtr, lp As IntPtr) As Boolean

    <DllImport("user32.dll")> _
    Private Shared Function EnumThreadWindows(tid As Integer, callback As EnumThreadWndProc, lp As IntPtr) As Boolean
    End Function

    <DllImport("kernel32.dll")> _
    Private Shared Function GetCurrentThreadId() As Integer
    End Function

    <DllImport("user32.dll")> _
    Private Shared Function GetClassName(hWnd As IntPtr, buffer As StringBuilder, buflen As Integer) As Integer
    End Function

    <DllImport("user32.dll")> _
    Private Shared Function GetDlgItem(hWnd As IntPtr, item As Integer) As IntPtr
    End Function

    <DllImport("user32.dll")> _
    Private Shared Function SendMessage(hWnd As IntPtr, msg As Integer, wp As IntPtr, lp As IntPtr) As IntPtr
    End Function

    <DllImport("user32.dll")> _
    Shared Function GetWindowRect(hWnd As IntPtr, ByRef rc As RECT) As Boolean
    End Function

    <DllImport("user32.dll")> _
    Shared Function MoveWindow(hWnd As IntPtr, x As Integer, y As Integer, w As Integer, h As Integer, repaint As Boolean) As Boolean
    End Function

    Structure RECT
        Public Left As Integer
        Public Top As Integer
        Public Right As Integer
        Public Bottom As Integer
    End Structure

    Public Sub New(owner As Form, Optional Custom_Font As Font = Nothing)
        mOwner = owner
        mFont = Custom_Font
        owner.BeginInvoke(New MethodInvoker(AddressOf findDialog))
    End Sub

    Private Sub findDialog()

        ' Enumerate windows to find the message box
        If mTries < 0 Then
            Return
        End If

        Dim callback As New EnumThreadWndProc(AddressOf checkWindow)

        If EnumThreadWindows(GetCurrentThreadId(), callback, IntPtr.Zero) Then
            If System.Threading.Interlocked.Increment(mTries) < 10 Then
                mOwner.BeginInvoke(New MethodInvoker(AddressOf findDialog))
            End If
        End If

    End Sub

    Private Function checkWindow(hWnd As IntPtr, lp As IntPtr) As Boolean

        ' Checks if <hWnd> is a dialog
        Dim sb As New StringBuilder(260)
        GetClassName(hWnd, sb, sb.Capacity)
        If sb.ToString() <> "#32770" Then Return True

        ' Got it, get the STATIC control that displays the text
        Dim hText As IntPtr = GetDlgItem(hWnd, &HFFFF)

        Dim frmRect As New Rectangle(mOwner.Location, mOwner.Size)
        Dim dlgRect As RECT
        GetWindowRect(hWnd, dlgRect)
        MoveWindow(hWnd, frmRect.Left + (frmRect.Width - dlgRect.Right + dlgRect.Left) \ 2, frmRect.Top + (frmRect.Height - dlgRect.Bottom + dlgRect.Top) \ 2, dlgRect.Right - dlgRect.Left, dlgRect.Bottom - dlgRect.Top, True)
        If hText <> IntPtr.Zero Then

            If mFont Is Nothing Then
                ' Get the current font
                mFont = Font.FromHfont(SendMessage(hText, WM_GETFONT, IntPtr.Zero, IntPtr.Zero))
            End If

            SendMessage(hText, WM_SETFONT, mFont.ToHfont(), New IntPtr(1))

        End If

        ' Done
        Return False

    End Function

    Public Sub Dispose() Implements IDisposable.Dispose
        mTries = -1
        mOwner = Nothing
        If mFont IsNot Nothing Then mFont.Dispose()
    End Sub

End Class








Eleкtro

#308
Un ayudante para manejar la aplicación dBpoweramp Music Converter, es el mejor conversor archivos de música a cualquier formato.

http://www.dbpoweramp.com/dmc.htm

Le agregué lo necesario para convertir a MP3, WAV, y WMA, se puede extender para agregar todos los demás codecs, pero es muy tedioso...

Tambiñen le agregué un par de eventos para capturar el progreso de conversión y mensajes de errores, el modo de empleo está explicado en los primeros comentarios.

PD: También existe una librería llamada dMcscriptinglib.dll, pero los autores de dbPowerAmp me dijeron que no es posible capturar el progreso de una conversión usando la librería, por ese motivo uso el executable CLI.

EDITO: Corregido un bug en las Enumeraciones del SampleRate de los Codecs, y he simplificado parte del código.

Código (vbnet) [Seleccionar]
#Region " CoreConverter Helper "



' [ CoreConverter Helper ]
'
' // By Elektro H@cker
'
'
' Instructions:
'
' 1. Add the "CoreConverter.exe" into the project,
'    together with the dbPoweramp Effects and Codec folders.
'
' Examples :
'
' -------------------
' CONVERT FILE TO MP3
' -------------------
' CoreConverter.Convert_To_MP3("C:\Input.wav", "C:\Output.mp3", _
'                              CoreConverter.Lame_Bitrate.kbps_320, _
'                              CoreConverter.Lame_Bitrate_Mode.cbr, _
'                              CoreConverter.Lame_Profile.SLOW, _
'                              CoreConverter.Lame_Quality.Q0_Maximum, _
'                              CoreConverter.Lame_Khz.Same_As_Source, _
'                              CoreConverter.Lame_Channels.auto, _
'                              { _
'                                CoreConverter.DSP_Effects.Delete_Output_File_on_Error, _
'                                CoreConverter.DSP_Effects.Recycle_Source_File_After_Conversion _
'                              }, _
'                              False, _
'                              CoreConverter.Priority.normal)
'
' -------------------
' CONVERT FILE TO WAV
' -------------------
' CoreConverter.Convert_To_WAV_Uncompressed("C:\Input.mp3", "C:\Output.wav", _
'                                           CoreConverter.WAV_Uncompressed_Bitrate.Same_As_Source, _
'                                           CoreConverter.WAV_Uncompressed_Khz.Same_As_Source, _
'                                           CoreConverter.WAV_Uncompressed_Channels.Same_As_Source, , False)
'
' -------------------
' CONVERT FILE TO WMA
' -------------------
' CoreConverter.Convert_To_WMA("C:\Input.mp3", "C:\Output.wma", _
'                              CoreConverter.WMA_9_2_BitRates.Kbps_128, _
'                              CoreConverter.WMA_9_2_Khz.Khz_44100, _
'                              CoreConverter.WMA_9_2_Channels.stereo, , False)
'
' ------
' EVENTS
' ------
' Public WithEvents Converter As New CoreConverter()
'
' Sub Converter_Progress(Progress As Integer, e As EventArgs) Handles Converter.PercentDone
'     ProgressBar1.Maximum = 59
'     ProgressBar1.Step = 1
'     ProgressBar1.PerformStep()
' End Sub
'
' Sub Converter_Message(Message As String, e As EventArgs) Handles Converter.Exited
'     ProgressBar1.Value = 0
'     MessageBox.Show(Message)
' End Sub



Public Class CoreConverter : Implements IDisposable

#Region " Variables "

   ' <summary>
   ' Gets or sets CoreConverter.exe executable path.
   ' </summary>
   Public Shared CoreConverter_Location As String = ".\CoreConverter.exe"

   ' Stores the CoreConverter process progress
   Private Shared CurrentProgress As Integer = 0

   ' Stores the CoreConverter process StandarOutput
   Private Shared StandardOutput As String = String.Empty

   ' Stores the CoreConverter process ErrorOutput
   Private Shared ErrorOutput As String = String.Empty

   ' Stores the next output character
   Private Shared OutputCharacter As Char = Nothing

   ' Stores the DSP Effects formatted string
   Private Shared Effects As String = String.Empty

#End Region

#Region " Events "

   ' <summary>
   ' Event raised when conversion progress changes.
   ' </summary>
   Public Shared Event PercentDone As EventHandler(Of PercentDoneEventArgs)
   Public Class PercentDoneEventArgs : Inherits EventArgs
       Public Property Progress As Integer
   End Class

   ' <summary>
   ' Event raised when CoreConverter process has exited.
   ' </summary>
   Public Shared Event Exited As EventHandler(Of ExitedEventArgs)
   Public Class ExitedEventArgs : Inherits EventArgs
       Public Property Message As String
   End Class

#End Region

#Region " Process Info "

   ' CoreConverter Process Information.
   Private Shared CoreConverter As New Process() With { _
       .StartInfo = New ProcessStartInfo With { _
       .CreateNoWindow = True, _
       .UseShellExecute = False, _
       .RedirectStandardError = True, _
       .RedirectStandardOutput = True, _
       .StandardErrorEncoding = System.Text.Encoding.Unicode, _
       .StandardOutputEncoding = System.Text.Encoding.Unicode}}

#End Region

#Region " CoreConverter Enumerations "

   ' Priority level of CoreConverter.exe
   Enum Priority
       idle
       low
       normal
       high
   End Enum

   ' DSP Effects
   Public Enum DSP_Effects
       Delete_Output_File_on_Error ' Delete failed conversion (not deletes source file).
       Delete_Source_File_After_Conversion ' Delete source file after conversion.
       Recycle_Source_File_After_Conversion ' Send source file to recycle bin after conversion.
       Karaoke_Remove_Voice ' Remove voice from file.
       Karaoke_Remove_Instrument ' Remove instruments from file.
       Reverse ' Reverse complete audio file.
       Write_Silence ' Write silence at start of file.
   End Enum

#End Region

#Region " Codec Enumerations "

#Region " MP3 Lame "

   Enum Lame_Bitrate
       kbps_8 = 8
       kbps_16 = 16
       kbps_24 = 24
       kbps_32 = 32
       kbps_40 = 40
       kbps_48 = 48
       kbps_56 = 56
       kbps_64 = 64
       kbps_80 = 80
       kbps_96 = 96
       kbps_112 = 112
       kbps_128 = 128
       kbps_144 = 144
       kbps_160 = 160
       kbps_192 = 192
       kbps_224 = 224
       kbps_256 = 256
       kbps_320 = 320
   End Enum

   Enum Lame_Bitrate_Mode
       cbr
       abr
   End Enum

   Enum Lame_Profile
       NORMAL
       FAST
       SLOW
   End Enum

   Enum Lame_Quality
       Q0_Maximum = 0
       Q1 = 1
       Q2 = 2
       Q3 = 3
       Q4 = 4
       Q5 = 5
       Q6 = 6
       Q7 = 7
       Q8 = 8
       Q9_Minimum = 9
   End Enum

   Enum Lame_Khz
       Same_As_Source
       khz_8000 = 8000
       khz_11025 = 11025
       khz_12000 = 12000
       khz_16000 = 16000
       khz_22050 = 22050
       khz_24000 = 24000
       khz_32000 = 32000
       khz_44100 = 44100
       khz_48000 = 48000
   End Enum

   Enum Lame_Channels
       auto
       mono
       stereo
       joint_stereo
       forced_joint_stereo
       forced_stereo
       dual_channels
   End Enum


#End Region

#Region " WAV Uncompressed "

   Enum WAV_Uncompressed_Bitrate
       Same_As_Source
       bits_8 = 8
       bits_16 = 16
       bits_24 = 24
       bits_32 = 32
   End Enum

   Enum WAV_Uncompressed_Khz
       Same_As_Source
       khz_8000 = 8000
       khz_11025 = 11025
       khz_12000 = 12000
       khz_16000 = 16000
       khz_22050 = 22050
       khz_24000 = 24000
       khz_32000 = 32000
       khz_44100 = 44100
       khz_48000 = 48000
       khz_96000 = 96000
       khz_192000 = 192000
   End Enum

   Enum WAV_Uncompressed_Channels
       Same_As_Source
       Channels_1_Mono = 1
       Channels_2_Stereo = 2
       Channels_3 = 3
       Channels_4_Quadraphonic = 4
       Channels_5_Surround = 5
       Channels_6_Surround_DVD = 6
       Channels_7 = 7
       Channels_8_Theater = 8
   End Enum

#End Region

#Region " WMA 9.2 "

   Enum WMA_9_2_BitRates
       Kbps_12 = 12
       Kbps_16 = 16
       Kbps_20 = 20
       Kbps_22 = 22
       Kbps_24 = 24
       Kbps_32 = 32
       Kbps_40 = 40
       Kbps_48 = 48
       Kbps_64 = 64
       Kbps_80 = 80
       Kbps_96 = 96
       Kbps_128 = 128
       Kbps_160 = 160
       Kbps_192 = 192
       Kbps_256 = 256
       Kbps_320 = 320
   End Enum

   Enum WMA_9_2_Khz
       Khz_8000 = 8
       Khz_16000 = 16
       Khz_22050 = 22
       Khz_32000 = 32
       Khz_44100 = 44
       Khz_48000 = 48
   End Enum

   Enum WMA_9_2_Channels
       mono
       stereo
   End Enum

#End Region

#End Region

#Region " Codec Procedures "

#Region " MP3 Lame "

   ' <summary>
   ' Converts a file to MP3 using Lame codec.
   ' </summary>
   Public Shared Sub Convert_To_MP3(ByVal In_File As String, _
                            ByVal Out_File As String, _
                            ByVal Bitrate As Lame_Bitrate, _
                            ByVal Bitrate_Mode As Lame_Bitrate_Mode, _
                            ByVal Encoding_Profile As Lame_Profile, _
                            ByVal Quality As Lame_Quality, _
                            ByVal Khz As Lame_Khz, _
                            ByVal Channels As Lame_Channels, _
                            Optional ByVal DSP_Effects() As DSP_Effects = Nothing, _
                            Optional ByVal Update_Tag As Boolean = True, _
                            Optional ByVal Priority As Priority = Priority.normal, _
                            Optional ByVal Processor As Short = 1)

       Get_Effects(DSP_Effects)

       Set_Main_Parametters("mp3 (Lame)", In_File, Out_File, If(Not Update_Tag, "-noidtag", ""), Effects, Priority.ToString, Processor.ToString)

       CoreConverter.StartInfo.Arguments &= _
       String.Format("-b {0} --{1} -encoding=""{2}"" -freq=""{3}"" -channels=""{4}"" --noreplaygain --extracli=""-q {5}""", _
                     CInt(Bitrate), _
                     Bitrate_Mode.ToString, _
                     Encoding_Profile.ToString, _
                     If(Khz = Lame_Khz.Same_As_Source, "", CInt(Khz)), _
                     If(Channels = Lame_Channels.auto, "", Channels), _
                     CInt(Quality))

       Run_CoreConverter()

   End Sub

#End Region

#Region " WAV Uncompressed "

   ' <summary>
   ' Converts a file to WAV
   ' </summary>
   Public Shared Sub Convert_To_WAV_Uncompressed(ByVal In_File As String, _
                                ByVal Out_File As String, _
                                ByVal Bitrate As WAV_Uncompressed_Bitrate, _
                                ByVal Khz As WAV_Uncompressed_Khz, _
                                ByVal Channels As WAV_Uncompressed_Channels, _
                                Optional ByVal DSP_Effects() As DSP_Effects = Nothing, _
                                Optional ByVal Update_Tag As Boolean = True, _
                                Optional ByVal Priority As Priority = Priority.normal, _
                                Optional ByVal Processor As Short = 1)

       Get_Effects(DSP_Effects)

       Set_Main_Parametters("Wave", In_File, Out_File, If(Not Update_Tag, "-noidtag", ""), Effects, Priority.ToString, Processor.ToString)

       CoreConverter.StartInfo.Arguments &= _
       String.Format("-compression=""PCM"" -bits=""{0}"" -freq=""{1}"" -channels=""{2}""", _
                     If(Bitrate = WAV_Uncompressed_Bitrate.Same_As_Source, "", CInt(Bitrate)), _
                     If(Khz = WAV_Uncompressed_Khz.Same_As_Source, "", CInt(Khz)), _
                     If(Channels = WAV_Uncompressed_Channels.Same_As_Source, "", CInt(Channels)))

       Run_CoreConverter()

   End Sub

#End Region

#Region " WMA 9.2 "

   ' <summary>
   ' Converts a file to WMA 9.2
   ' </summary>
   Public Shared Sub Convert_To_WMA(ByVal In_File As String, _
                                ByVal Out_File As String, _
                                ByVal Bitrate As WMA_9_2_BitRates, _
                                ByVal Khz As WMA_9_2_Khz, _
                                ByVal Channels As WMA_9_2_Channels, _
                                Optional ByVal DSP_Effects() As DSP_Effects = Nothing, _
                                Optional ByVal Update_Tag As Boolean = True, _
                                Optional ByVal Priority As Priority = Priority.normal, _
                                Optional ByVal Processor As Short = 1)

       Get_Effects(DSP_Effects)

       Set_Main_Parametters("Windows Media Audio 10", In_File, Out_File, If(Not Update_Tag, "-noidtag", ""), Effects, Priority.ToString, Processor.ToString)

       CoreConverter.StartInfo.Arguments &= _
       String.Format("-codec=""Windows Media Audio 9.2"" -settings=""{0} kbps, {1} kHz, {2} CBR""",
                     CInt(Bitrate), _
                     CInt(Khz), _
                     Channels.ToString)

       Run_CoreConverter()

   End Sub

#End Region

#End Region

#Region " Run Converter Procedure "

   Private Shared Sub Run_CoreConverter()

       CoreConverter.StartInfo.FileName = CoreConverter_Location
       CoreConverter.Start()

       While Not CoreConverter.HasExited

           OutputCharacter = ChrW(CoreConverter.StandardOutput.Read)

           If OutputCharacter = "*" Then
               CurrentProgress += 1 ' Maximum value is 59, so a ProgressBar Maximum property value would be 59.
               RaiseEvent PercentDone(CurrentProgress, Nothing)
           End If

           If CurrentProgress = 59 Then
               ' I store the last line(s) 'cause it has interesting information:
               ' Example message: Conversion completed in 30 seconds x44 realtime encoding
               StandardOutput = CoreConverter.StandardOutput.ReadToEnd.Trim
           End If

       End While

       ' Stores the Error Message (If any)
       ErrorOutput = CoreConverter.StandardError.ReadToEnd

       Select Case CoreConverter.ExitCode

           Case 0 : RaiseEvent Exited(StandardOutput, Nothing) ' Return StandardOutput
           Case Else : RaiseEvent Exited(ErrorOutput, Nothing) ' Return ErrordOutput

       End Select

       CurrentProgress = Nothing
       OutputCharacter = Nothing
       StandardOutput = Nothing
       ErrorOutput = Nothing
       Effects = Nothing
       CoreConverter.Close()

   End Sub

#End Region

#Region " Miscellaneous functions "

   ' <summary>
   ' Checks if CoreConverter process is avaliable.
   ' </summary>
   Public Shared Function Is_Avaliable() As Boolean
       Return IO.File.Exists(CoreConverter_Location)
   End Function

   ' Set the constant parametters of CoreConverter process
   Private Shared Sub Set_Main_Parametters(ByVal Codec_Name As String, _
                                           ByVal In_File As String, _
                                           ByVal Out_File As String, _
                                           ByVal Update_Tag As String, _
                                           ByVal Effects As String, _
                                           ByVal Priority As String, _
                                           ByVal Processor As String)

       CoreConverter.StartInfo.Arguments = _
       String.Format("-infile=""{0}"" -outfile=""{1}"" -convert_to=""{2}"" {3} {4} -priority=""{5}"" -processor=""{6}"" ", _
                     In_File, Out_File, Codec_Name, Update_Tag, Effects, Priority, Processor)

   End Sub

   ' Returns all joined DSP Effects formatted string
   Private Shared Function Get_Effects(ByVal DSP_Effects() As DSP_Effects) As String

       If DSP_Effects Is Nothing Then Return Nothing

       For Effect As Integer = 0 To DSP_Effects.Length - 1
           Effects &= String.Format(" -dspeffect{0}={1}", _
                                    Effect + 1, _
                                    Format_DSP_Effect(DSP_Effects(Effect).ToString))
       Next Effect

       Return Effects

   End Function

   ' Returns a DSP Effect formatted string
   Private Shared Function Format_DSP_Effect(ByVal Effect As String)

       Select Case Effect
           Case "Reverse" : Return """Reverse"""
           Case "Delete_Output_File_on_Error" : Return """Delete Destination File on Error="""
           Case "Recycle_Source_File_After_Conversion" : Return """Delete Source File=-recycle"""
           Case "Delete_Source_File_After_Conversion" : Return """Delete Source File="""
           Case "Karaoke_Remove_Voice" : Return """Karaoke (Voice_ Instrument Removal)="""
           Case "Karaoke_Remove_Instrument" : Return """Karaoke (Voice_ Instrument Removal)=-i"""
           Case "Write_Silence" : Return """Write Silence=-lengthms={qt}2000{qt}""" ' 2 seconds
           Case Else : Return String.Empty
       End Select

   End Function

#End Region

#Region " Dispose Objects "

   Public Sub Dispose() Implements IDisposable.Dispose
       ' CoreConverter_Location = Nothing ' Do not change if want to preserve a custom location.
       OutputCharacter = Nothing
       StandardOutput = Nothing
       ErrorOutput = Nothing
       CurrentProgress = Nothing
       Effects = Nothing
       CoreConverter.Close()
       GC.SuppressFinalize(Me)
   End Sub

#End Region

End Class

#End Region








Eleкtro

#309
Este snippet comprueba si un nombre de archivo contiene caracteres que no estén en la tabla ASCII (sin contar la tabla ASCII extendida)

Un ejemplo de uso sería, el que yo le doy:
yo dejo el PC descargando miles de archivos de música diariamente, muchos de los nombres de archivos descargados contienen caracteres rusos y otras mierd@s que luego me toca renombrar de forma manual porque no se pueden leer estos nomrbes de archivos por otros programas que uso.

PD: No contiene todos los caracteres de la tabla ASCII normal, recordemos que Windows no permite escribir ciertos caracteres ASCII en los nombres de archivo, asi que no es necesario añadir dichos caracteres la función, además le añadí el caracter "Ñ", y los caracteres de la tabla ASCII extendida yo los considero caracteres extraños, quizás el nombre de la función debería ser: "Filename Has Strange Characters? " :P.

#Region " Filename Has Non ASCII Characters "

   ' [ Filename Has Non ASCII Characters Function ]
   '
   ' // By Elektro H@cker
   '
   ' Examples :
   ' MsgBox(Filename_Has_Non_ASCII_Characters("ABC├│")) ' Result: True
   ' MsgBox(Filename_Has_Non_ASCII_Characters("ABCDE")) ' Result: False

    Private Function Filename_Has_Non_ASCII_Characters(ByVal [String] As String) As Boolean

        Dim Valid_Characters As String = ( _
            "abcdefghijklmnñopqrstuvwxyz" & _
            "ABCDEFGHIJKLMNÑOPQRSTUVWXYZ" & _
            "áéíóúÁÉÍÓÚàèìòùÀÈÌÒÙçÇ" & _
            "@#~€!·$%&()=!'ºª+-_.,;{}[]" & _
            ":\" & _
            "0123456789" & _
            " " _
        )

        Return Not [String].ToCharArray() _
                   .All(Function(character) Valid_Characters.Contains(character))

        ' Valid_Characters = Nothing

    End Function

#End Region