Results 1 to 6 of 6

Thread: Invalid character in a Base-64 string - help!

  1. #1
    Frenzied Member
    Join Date
    Oct 00
    Posts
    1,371

    Question Invalid character in a Base-64 string - help!

    Hi everyone,

    I found this code on this site in another thread and tried it. I am passing a string of a web url such as "http://www.website.com" and it gives me this error. How can I pass in the URL without this error?

    Code:

    Code:
        Private Sub saveURLToImage(ByVal url As String)
            If Not String.IsNullOrEmpty(url) Then
    
                Dim content As String = ""
                Dim webRequest__1 As System.Net.WebRequest = WebRequest.Create(url)
                Dim webResponse As System.Net.WebResponse = webRequest__1.GetResponse()
                Dim sr As System.IO.StreamReader = New StreamReader(webResponse.GetResponseStream(), System.Text.Encoding.GetEncoding("UTF-8"))
                content = sr.ReadToEnd()
                'save to file
                Dim b As Byte() = Convert.FromBase64String(content)
                Dim ms As New System.IO.MemoryStream(b)
                Dim img As System.Drawing.Image = System.Drawing.Image.FromStream(ms)
                img.Save("e:\default\wwwroot\site\images\report22.jpg", System.Drawing.Imaging.ImageFormat.Jpeg)
                img.Dispose()
                ms.Close()
            End If
        End Sub

  2. #2
    Frenzied Member Fishcake's Avatar
    Join Date
    Feb 01
    Location
    Derby, UK
    Posts
    1,090

    Re: Invalid character in a Base-64 string - help!

    Hi,

    Ultimately what are you trying to achieve here?

    Does the url you are using point directly to an image?

    In the code below
    Code:
    Dim b As Byte() = Convert.FromBase64String(content)
    would you expect content at this point to be a Base64 encoded image?

  3. #3
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 04
    Location
    The Granite City
    Posts
    21,733

    Re: Invalid character in a Base-64 string - HELP

    Hello,

    If you set a breakpoint on that line, and add content to a watch window, what is it's value?

    Gary

  4. #4
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 04
    Location
    The Granite City
    Posts
    21,733

    Re: Invalid character in a Base-64 string - help!

    Duplicate threads merged.

    Gary

  5. #5
    Frenzied Member
    Join Date
    Oct 00
    Posts
    1,371

    Re: Invalid character in a Base-64 string - help!

    The URL is pointed to a html page. Actually it will be an aspx page. Does this not work that way? I just saw the code and they said to use it to capture a webpage to an image. I've seen controls out there for this and I need to capture the page as an image where whatever the content is will be the size of the captured image. For example, I want to show a gridview control on an aspx page and capture that part as an image. Nothing else will be shown on the page anyways.

    Thanks

  6. #6
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 04
    Location
    The Granite City
    Posts
    21,733

    Re: Invalid character in a Base-64 string - help!

    Can you point us at the article/blog post that you are referring to?

    Gary

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •