473,385 Members | 1,546 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Generic Handler Problem - ASP.NET

6
Hello, i have the following problem with my Generic handler - it just doesn't execute! In my handler i have to get an icon from a file, save it to a bmp file and then write the icon to the response. Here is my code for the handler

public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "image/png";

try
{
int id = int.Parse(context.Request.QueryString["id"]);
Bitmap image = Icon.ExtractAssociatedIcon(_Default.Files[id].FullName).ToBitmap();
MemoryStream stream = new MemoryStream();
image.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
stream.WriteTo(context.Response.OutputStream);
stream.Flush();
context.Response.Flush();
}
catch (UnauthorizedAccessException ex)
{
context.Response.Write(ex.Message);
}
catch (FileNotFoundException ex)
{
context.Response.Write(ex.Message);
}
}

And here is how i call it -

for (int i = 0; i != Files.Length; i++)
{
node = new TreeNode(Files[i].Name);
node.ImageUrl = "/HandlerImages.ashx?id="+ i.ToString();
//node.ImageUrl = "Images.aspx?id=" + i.ToString();
treeViewFiles.Nodes.Add(node);
}

When i start the application i can see that no icons had been drowned to the response. When trying to debug the same results occur. I have looked in some articles about handlers and everything seems to be ok, but it just dont work! When i try the same thing with an aspx page instead of handler it works... but this is not the way that images are supposed to be handled in asp. Help :(
Oct 19 '08 #1
1 1789
danp129
323 Expert 256MB
ASP.Net questions are better answered in the .Net forum http://bytes.com/forum/forum131.html
Oct 20 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Csaba Gabor | last post by:
The usual example shown for trapping for failure of COM instantiation (Windows systems) is something like (see for example http://at2.php.net/manual/en/class.com.php): $word = new...
2
by: Jon Davis | last post by:
The garbage handler in the .NET framework is handy. When objects fall out of scope, they are automatically destroyed, and the programmer doesn't have to worry about deallocating the memory space...
5
by: Richard Brown | last post by:
Ok, I've been looking through the .NET SDK docs and stuff. I'm wondering if you can provide a control extender that does generic validation or functionality just by dropping it on the form. For...
8
by: Woody Splawn | last post by:
Could someone give me a suggestion for writing generic code in a validating event for trimming the value of a textbox entry? I thought something like the following might work but it does not. ...
6
by: David Veeneman | last post by:
I have several events that pass a value in their event args. One event passes an int, another a string, another a DateTime, and so on. Rather than creating a separate set of event args for each...
0
by: Mikkel Blanné | last post by:
I haven't been able to find any references to using this combination of technologies (remoting + generic methods + method overloading). I don't think the problem has to do with C#, but I couldn't...
1
by: Chris | last post by:
I want to create a generic event handler for some controls I am dynamically adding via a class. My class compiles OK but when I change the text in the textboxes it doesn't do anything. What am I...
10
by: phancey | last post by:
I'm quite new to generics. I have 2 generic classes: MyClass<Tand MyOtherClass<T>. MyClass<Thas 2 public Add methods Add(MyOtherClass<T>); Add(MyOtherClass<Wrapper<T>>); (Wrapper<Tis another...
1
by: eeasss | last post by:
Hello, i have the following problem with my Generic handler - it just doesn't execute! In my handler i have to get an icon from a file, save it to a bmp file and then write the icon to the response....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.