Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Data Signals to file...

Status
Not open for further replies.

blah2468

Technical User
Mar 14, 2007
11
CA
Hi there,
I'm supposed to process an xml file. In this xml file content of a pdf file is returned as data-signals (hexa-decimal sequence of alph-numerical characters)

The format of this xml file (hugely simplified) looks like this:
Code:
<EMBEDDED_FILE _Extension=".pdf">
      <DOCUMENT>...</DOCUMENT>
</EMBEDDED_FILE>

Now, I'm supposed to grab this data that is capsulated between the <DOCUMENT> tag, and turn it into a pdf file. I have absolutly no idea on how to do this... any help is much appreciated
 
have you tried writing the <document> text to a file and saving with a pdf extension? I would start there.

if that doesn't work. convert the string into a binary array and then write the array to a file with a pdf extension.

one of these to methods should work.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Hey thanx for the tip; that's exactly what I did to begin with.. no luck

Following 3 lines do the magic though:
Code:
Dim bt() As Byte
bt = System.Convert.FromBase64String(base64String)
System.IO.File.WriteAllBytes(pdfReportFilePathnName, bt)


And here's the complete function i use. I simply pass the function an xmlDocument and tell it where to store the embeded file:
Code:
    Public Shared Function Base64ToFile(ByVal xmlDoc As XmlDocument, ByVal pdfReportFilePathnName As String) As String
        'generate the file:
        Try
'get base64 string representing the file
            Dim base64String As String = xmlDoc.GetElementsByTagName("DOCUMENT").Item(0).InnerText

            Dim bt() As Byte
            bt = System.Convert.FromBase64String(base64String)
            System.IO.File.WriteAllBytes(pdfReportFilePathnName, bt)

            Return "Successfully decoded the embeded base-64 report file" + vbCrLf

        Catch ex As Exception
            Return "Failed generating the embeded file due to the following unanticipated error: " + vbCrLf + _
                    ex.Message
        End Try
    End Function

CHEERS!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top