Click here to Skip to main content
Sign Up to vote bad
good
See more: ASP.NET
Hi.. Friends, I have the following method in my c#.net web application code to get bytes of the images
public byte[] pstFile(HttpPostedFile hf)
    {       
        Stream fs = default(Stream);
        byte[] bytes1 = null;
        byte[] postfile = null;
        fs = hf.InputStream;
        BinaryReader a = new BinaryReader(hf.InputStream);
        BinaryReader br1 = new BinaryReader(fs);
        bytes1 = a.ReadBytes(hf.ContentLength);
        postfile = bytes1;
        return postfile;
    }
 
but, the problem is that it return the 0 bytes and while I write the same code in another application it is working fine.
 
So, please tell me where I am wrong.
 
Thanks & regards
Parveen Rathi
Posted 30 Apr '12 - 23:11


1 solution

You do realize that the majority of your code is completely useless, don't you? The only effective code you have there is:
public byte[] pstFile(HttpPostedFile hf)
    {
    BinaryReader a = new BinaryReader(hf.InputStream);
    return  a.ReadBytes(hf.ContentLength);
    }
So I suspect that if this worked in a different application, it was because it wasn't anything like the code you are showing us...
  Permalink  
Comments
Parveen Rathi - 1 May '12 - 5:59
Thanks for your reply but I am using the same code on both application. is here any other way to display image without saving it to folder
OriginalGriff - 1 May '12 - 6:03
You don't have to save any image to a folder to display it - but how you do it depends on what you are trying to achieve, and how you have implemented things so far. Where does hf come from? Where do the bytes go?
Parveen Rathi - 1 May '12 - 6:32
hf is come from the httpFileCollection, and i want to display the uploaded image preview to the users without saving the image to folder

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 398
1 Arun Vasu 381
2 OriginalGriff 345
3 Aarti Meswania 210
4 Maciej Los 196
0 Sergey Alexandrovich Kryukov 9,755
1 OriginalGriff 7,559
2 CPallini 4,018
3 Rohan Leuva 3,362
4 Maciej Los 2,951


Advertise | Privacy | Mobile
Web01 | 2.6.130523.1 | Last Updated 1 May 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid