Photo Uploading Error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gyanendar
    New Member
    • Jun 2007
    • 90

    Photo Uploading Error

    Hi All,

    In my web apllication ,I am saving the Photo into the DataBase.
    For doing this i am reading the content of picture in byte[] as:
    Code:
     byte[] img = new byte[fuPhoto.PostedFile.ContentLength];
     FileStream fs = new FileStream(fuPhoto.PostedFile.FileName, FileMode.Open);
     BinaryReader br = new BinaryReader(fs);
     br.Read(img, 0, fuPhoto.PostedFile.ContentLength);
    I am browsing the picture from some location say C:\Photo\..

    In the second line of code..Its throwing exception:
    Could not find file 'c:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE \sumit sachdeva.jpg'.

    Please help.
    Regards,
    Gyanendar
    Last edited by Frinavale; Jan 15 '10, 02:26 PM. Reason: Please post code in [code] ... [code] tags. Added code tags.
  • sanjib65
    New Member
    • Nov 2009
    • 102

    #2
    Your error says file does not exist.

    Please try to give the codes that had generated the exceptions. You need not give the full code but the crux.

    Secondly, I got a very good link that you might find useful for uploading Images.

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #3
      Ok the problem is that the PostedFile.File Name is the name of the file being uploaded. When the server attempts to create a stream to this file it is looking for the file in the current operating directory....bu t the file obviously isn't there...because the file is not on the server.

      What you should consider using is the FileContent property to retrieve the stream to the file instead of attempting to create the stream as you currently are doing.

      -Frinny

      Comment

      • daonho
        New Member
        • Apr 2008
        • 18

        #4
        It looks like you are trying grab content on client computer. I don't believe it's possible to do that. You'll probably need to upload the file to your web server, then process the reading from there. Once you're done, you can just remove that file from the server. Don't forget to include Server.MapPath( filename)

        Comment

        Working...