image with no extension HttpWebRequest

Last post 06-25-2009 11:07 AM by jbassett. 4 replies.

Sort Posts:

  • image with no extension HttpWebRequest

    06-23-2009, 11:20 AM
    • Member
      12 point Member
    • jbassett
    • Member since 01-02-2008, 11:11 PM
    • Posts 194

    I'm trying to pull images from our server but they are written on-the-fly with no extension (like a .jpg or .gif) for instance.

     Even if I set the content type like this:

        myReq.ContentType = "image/jpg"

     ...It still fails.

     

    IF I set the content type I get this error:

    System.NullReferenceException: Object reference not set to an instance of an object.

    If I do not set the content type I get this error:

    System.IO.DirectoryNotFoundException: Could not find a part of the path 'd:\imagedirectorytosavein\'.
    System.IO.DirectoryNotFoundException:
       at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)

     

    ...But Regardless I always get an error. If I use an image that has a .jpg or .gif after it....no problem.

     

    Thanks for your help.

  • Re: image with no extension HttpWebRequest

    06-23-2009, 7:21 PM
    • All-Star
      97,380 point All-Star
    • mbanavige
    • Member since 11-06-2003, 8:29 AM
    • New England, USA
    • Posts 10,290
    • Moderator
      TrustedFriends-MVPs

    please post the code that causes the error.

    Mike Banavige
    ~~~~~~~~~~~~
    Need a site code sample in a different language? Try converting it with: http://converter.telerik.com/
  • Re: image with no extension HttpWebRequest

    06-23-2009, 7:34 PM
    • Member
      12 point Member
    • jbassett
    • Member since 01-02-2008, 11:11 PM
    • Posts 194

    Thanks! Here you go...

     



                Dim b As Byte()
                Dim myReq As HttpWebRequest = Nothing
                Dim myResp As HttpWebResponse
                Dim ExceptionExists As Integer = 0
                Try

                    myReq.ContentType = "image/jpg" ' Sometimes I add this and sometimes I don't


                    myReq = CType(WebRequest.Create(url), HttpWebRequest) ' THIS SEEMS TO BE THE LINE THAT KILLS IT
                  

                    myResp = CType(myReq.GetResponse(), HttpWebResponse)
                Catch ex As WebException 
           
                    ExceptionExists = 1

                
                End Try

     

  • Re: image with no extension HttpWebRequest

    06-23-2009, 7:56 PM
    Answer
    • All-Star
      97,380 point All-Star
    • mbanavige
    • Member since 11-06-2003, 8:29 AM
    • New England, USA
    • Posts 10,290
    • Moderator
      TrustedFriends-MVPs

    in your example, you're setting the ContentType property of myReq before you have actually created the HttpWebRequest instance, so myReq would be null and that would seem to be the cause of the null reference exception

    Mike Banavige
    ~~~~~~~~~~~~
    Need a site code sample in a different language? Try converting it with: http://converter.telerik.com/
  • Re: image with no extension HttpWebRequest

    06-25-2009, 11:07 AM
    • Member
      12 point Member
    • jbassett
    • Member since 01-02-2008, 11:11 PM
    • Posts 194

    Yep, that was it. Thanks for the help.

Page 1 of 1 (5 items)