Convert GUID to String

Posted on 2009-04-23
Last Modified: 2012-05-06
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

Question by:manfredfield
    LVL 6

    Expert Comment

    Try this:

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

    Open in new window

    LVL 6

    Expert Comment

    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.
    LVL 1

    Author Comment

    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
    LVL 6

    Accepted Solution

    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()))

    Featured Post

    Training Course: Java/J2EE and SOA

    This course will cover both core and advanced Java concepts like Database connectivity, Threads, Exception Handling, Collections, JSP, Servlets, XMLHandling, and more. You'll also learn various Java frameworks like Hibernate and Spring.

    Join & Write a Comment

    Normally a window is moved by clicking on the caption bar and dragging. You may want your user to be able to move borderless forms or move a form by clicking anywhere in the form without the limitation to the caption bar. There are many ways to do i…
    Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (…
    This video discusses moving either the default database or any database to a new volume.
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now