tags:

views:

38

answers:

2

byte.eml file is having image base64 encoded value ..and i am tring to open it in browser ...but this is not populating image file....plz help me out..

this is code...
Dim oFile As System.IO.File Dim orEAD As System.IO.StreamReader

orEAD = oFile.OpenText("E:\mailbox\P3_hemantd.mbx\byte.eml")
Dim content As String
content = ""

''Dim intsinglechr As Integer
''Dim csinglechr As String

While orEAD.Peek <> -1
   content = content & Chr(orEAD.Read)
    content = Replace(content, vbCrLf, "")
    content = Replace(content, vbTab, "")
    content = Replace(content, " ", "")

End While
Response.ContentType = "image/jpeg"
Response.BinaryWrite(Convert.FromBase64String(content))
A: 

Does function Convert.FromBase64String(content) work correct? Try write to file it.

its working but it generating but result is unexpected....eg����JFIF��;CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), quality = 85 ��C !"$"$an i suppose to write it like ...this give errorResponse.WriteFile(Convert.FromBase64String(content))error.value of type '1-dimensional array of byte' cannot be converted to 'String'one thing i want yoou to clear byte.eml file only having the base 64 encded image file.i try it to convert from diff utility this working .so need asp.net codeing for handling file based decoding
manish
A: 

The problem is that the content of byte.eml is not a base64 encoded image, it is a MIME document.

You need to parse the MIME document and then get your image.

You can google "C# MIME MAIL PARSING".

Here is a related SO question to get you started

UPDATE:

Ok, so let's assume that you actually do have a valid representation of an image as a base64 string...

<%@ Page Language="VB" %>

<%@ Import Namespace="System.IO" %>

<script runat="server">
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load


        Dim bytes As Byte() = File.ReadAllBytes(Server.MapPath("Chrysanthemum.jpg"))
        Dim base64 As String = Convert.ToBase64String(bytes)

        '' base64 is what you say you have


        Dim newBytes As Byte() = Convert.FromBase64String(base64)
        Response.ClearContent()
        Response.ClearHeaders()
        Response.ContentType = "image/jpeg"
        Response.BinaryWrite(newBytes)
        Response.End()

    End Sub

</script>

This code works, if you substitute the text you have for base64 and it doesn't work, you have not a valid base64 string representation of an image.

Update 2:

This will read the text file that you say contains base64 and write it to the response.

If it still does not work then you have another question to ask:

How do I properly extract a base64 section from a MIME email?

<%@ Page Language="VB" %>
<%@ Import Namespace="System.IO" %>
<script runat="server">
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Dim base64 As String = File.ReadAllText("E:\mailbox\P3_hemantd.mbx\byte.eml")

        Dim newBytes As Byte() = Convert.FromBase64String(base64)
        Response.ClearContent()
        Response.ClearHeaders()
        Response.ContentType = "image/jpeg"
        Response.BinaryWrite(newBytes)
        Response.End()
    End Sub
</script>
Sky Sanders
byte.eml file having only base 64 encoded image...i extract it from eml file .and now i am tring it to open in web browser through asp.net....but i am not getting result...help me suppose i am having txt file content base 64 encoded image.eg"R0lGODlhagAwAOZ/ANHU+uLj4wZ0b4yT+oaHitfX11hj+H+H+xMn6Oj29xzVy9L19BHGvauw+zVF8sjIyEhV+Efaz2pvozKf3b29vQ0m1v7+/u7u7gWJgwlgqoOzsSo67yTd0yXXzODi+wV/..........."so send my exact asp.net code for converting abouve base 64 encoded text to image .
manish
boss you are great...i tried your code ..and its working...i bit happy after spending 10 hour something got happening.... let see what my code say.... will you help me once more..... send me code for read txt file content and convert it Byte i am asking for replacement of this.. Dim bytes As Byte() = File.ReadAllBytes(Server.MapPath("Chrysanthemum.jpg")) Dim base64 As String = Convert.ToBase64String(bytes) i want to store in base64 my file content
manish
thanks frnd i got solved my problem....thanks alot......i need your mail...for further any help...
manish
@Manish - great, glad I could help. Welcome to StackOverflow. Now, I did my job in helping you, your job is to click the up arrow next to the '0' that is next to my answer to indicate pleasure with my answer and then click the check mark to indicate that this answer helped you solve your problem.
Sky Sanders