Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4898
  • Last Modified:

Convert GUID to String vb.net

Hi, We're reading a GUID out of our Active Directory but we need to convert it into a string to be stored as plain text.

I've tried converting it from a byte array, doing casting but nothing seems to work

Please help.
Dim b() As Byte
                        Dim utf As New System.Text.UTF7Encoding()
                        b = utf.GetBytes(result.Properties("msExchMailboxGuid")(0))
                        Dim s As String = utf.GetString(b)

Open in new window

0
manfredfield
Asked:
manfredfield
  • 3
1 Solution
 
alex_pavenCommented:
Try this:

Dim g as New Guid(bytes)
Dim s as String = g.ToString()

Open in new window

0
 
alex_pavenCommented:
Note: Guid.ToString() accepts an argument that changes the format of the result, if you want it any different from the standard display format of a GUID; see msdn for possible values.
0
 
manfredfieldAuthor Commented:
Hi Alex,

I'm get this now Error      

4      Overload resolution failed because no accessible 'New' can be called without a narrowing conversion:
    'Public Sub New(g As String)': Argument matching parameter 'g' narrows from 'Object' to 'String'.
    'Public Sub New(b() As Byte)': Argument matching parameter 'b' narrows from 'Object' to '1-dimensional array of Byte'.      C:\Development Projects\Projects\Active Directory Sync\Active Directory Sync\Form1.vb      338      29      Active Directory Sync
0
 
alex_pavenCommented:
I have no idea what exactly your object is; go into debug mode and inspect the variable, then cast it to the underlying type before creating the Guid, probably like this:
Dim g as New Guid(DirectCast(o, Byte()))
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now