views:

36

answers:

2

As it states, I need to upload a file, and then use it in the pre_init event of a second page. Server lifecycle prevents this (as pre_init happens before the event handlers), that's fine, so the only way I can see around is to use page1 to upload the file, then do a response.redirect to the page2 where I can use the file in the pre_init. But this seems a)convulted, and b)needs me to pass the uploaded filename through to the second page.

Is there anyway around this, or am I going to have to like and lump it?

(I need the pre_init event to add steps to a wizardcontrol, and deserialise the file to get the objects to add to it).

Thanks

+2  A: 

You should be able to use Request.Files directly from pre_init:

protected void Page_PreInit(object sender, EventArgs e)
{
    HttpPostedFile file = Request.Files["IDOfFileUploadControl"];
}
Mike Comstock
Cheers, this is what I needed, didn't know about Request.Files
Psytronic
Great, glad I could help. Don't forget to mark as answered :)
Mike Comstock
A: 

Cross-Page posting seems like a solution. You can get the FileUpload control from previous page like this:

if (Page.PreviousPage != null)
{
    FileUpload prev = 
        (FileUpload)Page.PreviousPage.FindControl("FileUpload1");
    if (prev != null)
    {
        // Operations.
    }
}

I haven't tried if it works in Pre_Init event but it worth trying.

For more information about Cross-Page Posting:

http://msdn.microsoft.com/en-us/library/ms178139.aspx

Musa Hafalır