Click here to Skip to main content
15,908,112 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi.. Friends, I have the following method in my c#.net web application code to get bytes of the images
C#
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

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:
C#
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...
 
Share this answer
 
Comments
Parveen Rathi 1-May-12 5:59am    
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:03am    
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:32am    
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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900