Click here to Skip to main content
15,881,812 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi friends,
I am tring to show an image in image control using stream class in asp.net.
(using this code in handler file) but getting no response .
plz help



XML
FileStream MyFileStream;
                    long FileSize;

                    MyFileStream = new FileStream("~/images/Avatar.jpg", FileMode.Open);
                    FileSize = MyFileStream.Length;

                    byte[] Buffer = new byte[(int)FileSize];
                    MyFileStream.Read(Buffer, 0, (int)FileSize);
                    MyFileStream.Close();

                   //Response.Write("<b>File Contents: </b>");
                    context.Response.BinaryWrite(Buffer);
Posted

1 solution

Sounds like you are trying to save/retrieve image using HTTP Handler, if so: Generic Image Handler Using IHttpHandler[^]
 
Share this answer
 
Comments
BALBINDER4u 16-Feb-13 7:30am    
basic error is in this line ( System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Program Files\Common Files\Microsoft Shared\DevServer\10.0\~\Avatar.jpg'.)


MyFileStream = new FileStream("~/Avatar.jpg", FileMode.Open);

error is
( System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Program Files\Common Files\Microsoft Shared\DevServer\10.0\~\Avatar.jpg'.)
Sandeep Mewara 16-Feb-13 7:47am    
It's clear that the path specified and expected does not match.

Give an absolute path or use ResolveUrl method. Currently, yout '~/Avatar.jpg' is being looked in some programfiles 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