Click here to Skip to main content
12,457,259 members (55,205 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: ASP.NET
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



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 15-Feb-13 20:14pm

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Sounds like you are trying to save/retrieve image using HTTP Handler, if so: Generic Image Handler Using IHttpHandler[^]
  Permalink  
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.160826.1 | Last Updated 16 Feb 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100