Home All Groups Group Topic Archive Search About
Author
22 Mar 2006 4:23 AM
David Thielen
Hi;

When there is a post to my code behind, if I read the FileUpload file, the
filename disappears from the control. How can I keep the filename in the
control so the user doesn't think it's gone?

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

Author
22 Mar 2006 10:13 AM
Steven Cheng[MSFT]
Hi Dave,

As for the fileupload control, it won't persist the filename after the post
in which the file stream is uploaded. This is because the file stream only
exists in the postback of the uploading post, after that , no filestream
exists in the request, so there is no reason to persist the filename any
longer. This also confirm to the html <input type="file" ...> element's
natural behavior.  BTW, if you do need to persist the filename(of the
latest uploaded file), you can consider manually store it in the fileupload
control's attributes colleciton for sequential use. For example:

======================
protected void btnSubmit_Click(object sender, EventArgs e)
    {
        if (fu1.HasFile && fu1.FileName != null)
        {
            fu1.Attributes["filename"] = fu1.FileName;
        }
    }
=======================

then, in later postback, we can access the value through
fu1.Attriburtes["filename"]

Hope this helps you.


Regards,

Steven Cheng
Microsoft Online Community Support


==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================


This posting is provided "AS IS" with no warranties, and confers no rights.
Author
22 Mar 2006 2:20 PM
David Thielen
Hi;

My problem is as follows. We have two buttons that will do a post back where
we need to read the file, but we stay on the same page. One is a "test"
button that verifies the format of the file is good (must be rtf or wordml)
and one parses the file for some data that is then displayed on the page.

The problem we have is users click that button, see the filename disappear,
and think the page has lost the file. Any suggestion on how to handle this so
users don't think we lost the file?

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com



Show quoteHide quote
"Steven Cheng[MSFT]" wrote:

> Hi Dave,
>
> As for the fileupload control, it won't persist the filename after the post
> in which the file stream is uploaded. This is because the file stream only
> exists in the postback of the uploading post, after that , no filestream
> exists in the request, so there is no reason to persist the filename any
> longer. This also confirm to the html <input type="file" ...> element's
> natural behavior.  BTW, if you do need to persist the filename(of the
> latest uploaded file), you can consider manually store it in the fileupload
> control's attributes colleciton for sequential use. For example:
>
> ======================
>  protected void btnSubmit_Click(object sender, EventArgs e)
>     {
>         if (fu1.HasFile && fu1.FileName != null)
>         {
>             fu1.Attributes["filename"] = fu1.FileName;
>         }
>     }
> =======================
>
> then, in later postback, we can access the value through
> fu1.Attriburtes["filename"]
>
> Hope this helps you.
>
>
> Regards,
>
> Steven Cheng
> Microsoft Online Community Support
>
>
> ==================================================
>
> When responding to posts, please "Reply to Group" via your newsreader so
> that others may learn and benefit from your issue.
>
> ==================================================
>
>
> This posting is provided "AS IS" with no warranties, and confers no rights.
>
>
>
>
>
>
>
>
>
>
>
>
Author
23 Mar 2006 2:22 AM
Steven Cheng[MSFT]
Thanks for your further description Dave,

So you have two postback buttons which will be used to process the same
uploaded file in different postback events, correct? I'm afraid this is not
supported under the default behavior since the uploaded filestream/ and
file name won't be persisted between two postbacks (unless the client user
reselect the same file to upload before postback).

For your scenario, I think you need to temporarly save the uploaded
filestream in a temp dir on the server, also persist the filename through
the means I mentioned in the former thread, thus, in later postback, you
can still access the temp file and do the manipulation or retrieve info
from it. this can avoid the client user to resubmit the same file again,
however, it require us to do more configuration on the server-side.

Regards,

Steven Cheng
Microsoft Online Community Support


==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may

learn and benefit from your issue.

==================================================


This posting is provided "AS IS" with no warranties, and confers no rights.
Author
23 Mar 2006 3:57 AM
David Thielen
ok - thanks. I need to rethink how we present this to the user.

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com



Show quoteHide quote
"Steven Cheng[MSFT]" wrote:

> Thanks for your further description Dave,
>
> So you have two postback buttons which will be used to process the same
> uploaded file in different postback events, correct? I'm afraid this is not
> supported under the default behavior since the uploaded filestream/ and
> file name won't be persisted between two postbacks (unless the client user
> reselect the same file to upload before postback).
>
> For your scenario, I think you need to temporarly save the uploaded
> filestream in a temp dir on the server, also persist the filename through
> the means I mentioned in the former thread, thus, in later postback, you
> can still access the temp file and do the manipulation or retrieve info
> from it. this can avoid the client user to resubmit the same file again,
> however, it require us to do more configuration on the server-side.
>
> Regards,
>
> Steven Cheng
> Microsoft Online Community Support
>
>
> ==================================================
>
> When responding to posts, please "Reply to Group" via your newsreader so
> that others may
>
> learn and benefit from your issue.
>
> ==================================================
>
>
> This posting is provided "AS IS" with no warranties, and confers no rights.
>
>
>
>
Author
23 Mar 2006 5:49 AM
Steven Cheng[MSFT]
OK. Please feel free to post here if there is any further problem.

Regards,

Steven Cheng
Microsoft Online Community Support


==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may

learn and benefit from your issue.

==================================================


This posting is provided "AS IS" with no warranties, and confers no rights.