views:

186

answers:

2

I would like to know what events get executed (if any) after a user has selected to submit a file for upload on an ASP.NET page.

Would I need to tweak anything at the IIS level?

Should the page life cycle events be triggered when the user uploads a file?

I see different behaviour on my development server from Visual Studio in regards to the IIS server I deploy to:

on the development server, the life cycle events get triggered when a file gets selected, on the deployed server they don't..

What classes would I need to override, what web.config settings should I change, in order to tweak the default behaviour of the upload?

The problem I am having, is finding documentation on how to have code executed before the file gets uploaded, but after a file got selected.

P.S. this is related to a previous question of mine here, but approached in a very different way in the hopes of understanding the whole upload process, so I thought it's a different question all together.

+1  A: 

No, it has no event for file upload(maybe on .net 4)

what I did was a class that derives from the upload object and on OnLoad event something like this:

public event EventHandler OnUpload;
protected void OnLoad(...){
   if (this.HasFile && this.OnUpload != null)
     this.OnUpload(this, EventArgs.Empty);
}

sort of that.

Joe

-- Edit: Oh, I re-read your post and you want to know when people selects a file but it is not yet sent to the server? thats javascript. Server side can't know when people select it without sending a information to the server. You can develop a WebService function that is called when the onchanged of the input has been called, but I don't know if thats a good idea. Can you use javascript for this?

try:

  <asp:textbox id="t1" runat="server"/>

on code behind:

  t1.Attributes.Add("onchange", "alert('it changed its value: ' + this.value);");

hope it helps.

Jonathan
yes, javascript could trigger stuff on the server end, but I wonder if I could catch something with the httpcontext so that I can actually manipulate what is going on.. check file size of upload and so on.
Ric Tokyo
what puzzles me is the fact that Cassini, the in built server in Visual Studio does trigger events when you select a file.. why is this? and if so, why would it trigger on the Cassini server and not on the deployed IIS ?
Ric Tokyo
Cassini is the specialized web server for Visual Studio, it probably has integration with IE or even COM controls of webbrowsers, so it is not the same thing on outside visual studio... You can check the file with javascript, but the most you will do is see the name of the file and the path in thecomputer. YOu can use activeX to get file size, but it will only work on IE, here: http://forums.digitalpoint.com/showthread.php?t=6704. For other browsers I think flash may help you. Did we help you?
Jonathan
+1  A: 

To execute code before upload, it would have to be JavaSript code running in the browser. See my answer to a question about filtering file uploads based on type:

http://stackoverflow.com/questions/1576231/how-to-filter-which-files-can-be-seen-on-upload-dialog-box/1576342#1576342

gWiz
Hi, yes, I have found this useful to a degree, you see I am trying to check the file size, I don't think this can be done with JavaScript.. in the end I would like to measure the size of the request which holds also the size of the file to be sent
Ric Tokyo
I believe you would have to look into a Flash or Silverlight uploader for that. I wouldn't be surprised if there was a free uploader that provided that information through JavaScript hooks. Unfortunately, I don't know of any off the top of my head.
gWiz
yes, any ActiveX, Flash or SilverLight app would do, JavaScript wouldn't be able to do this I think though..(that would be nice) :) thanks
Ric Tokyo