Click here to Skip to main content
11,649,294 members (80,652 online)
Rate this: bad
good
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 at 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 at 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
0 CPallini 370
1 F-ES Sitecore 364
2 OriginalGriff 324
3 Kornfeld Eliyahu Peter 324
4 Sergey Alexandrovich Kryukov 254
0 OriginalGriff 1,512
1 Sergey Alexandrovich Kryukov 1,022
2 jyo.net 994
3 DamithSL 986
4 CPallini 945


Advertise | Privacy | Mobile
Web03 | 2.8.150804.4 | Last Updated 16 Feb 2013
Copyright © CodeProject, 1999-2015
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