ASP.net 2.0 need to grab file name from fileupload control to put in a form on another page

4 views
Skip to first unread message

pauld

unread,
May 8, 2008, 12:52:56 AM5/8/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Hi-
I need to put the name of a file that a user has uploaded into a text
field on a form on another page for insertion (along with a bunch of
other form fields) into a database. Is there an easy way to do this?
I'm sure there is but I got the end of semester brain death....

All i need is the "photoname.png" or whatever- no path, no validation,
no size limit.

FTR- this is a fileupload control being implemented on a page built
with Expression 1.o and VS2005 using asp.net 2.0 and VB. It allows
users to upload a photo whose file name is included with other db
data.


TIA-
Paul

Cerebrus

unread,
May 8, 2008, 2:06:53 PM5/8/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Assuming you know how to retrieve the name and other properties of the
file selected through the FileUpload control, it boils down to a
problem of transferring information from one page to another. There
are about a thousand (okay, maybe a little less ! ;-) ) ways to do
this.

pauld

unread,
May 8, 2008, 3:27:33 PM5/8/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting


On May 8, 12:06 pm, Cerebrus <zorg...@sify.com> wrote:
> Assuming you know how to retrieve the name and other properties of the
> file selected through the FileUpload control, it boils down to a
> problem of transferring information from one page to another. There
> are about a thousand (okay, maybe a little less ! ;-) ) ways to do
> this.
>

Ah, there's the problem. I haven't used the FileUpload control before,
so I don't know how to work with it, really. Let me ask another
question: my understanding is that the fileupload must be on its own
form, so I have to do this the way I am doing it, yes?

Basically this is a registration form where the admins or registrants
have the option of associating a photo with the record when it is
created. As it stands now I have an "Upload Photo" link that opens the
page with the fileupload control on it. You browse to the file.
etc,etc and once the file is uploaded successfully I want some way
that when the user returns to the page or form that the photo's name
is filled into the space where it can be stored along with the rest of
the database info when the user clicks "Create Record"

I have opted to not store the photos in the db as binary data as it is
easier to work with datagridview and other asp.net data presentation
controls with just the filename (this I do know how to do).

So, if there's a way to do what I describe, or a better way to do the
whole thing, I would be very much obliged.

Thanks again,
Paul

pauld

unread,
May 8, 2008, 4:01:49 PM5/8/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Update: I can get the filename as a string var when I do the
fileupload. So now I need to have that var placed in the photo name
textbox. I know there are easy ways to do this but it has been almost
two years since I have dome anything with vb/asp.net so I am extremely
rusty.

Ideally the user would click the "upload photo" link with the form,
browse to the file, do the upload and then simply return to the form,
but
if I can get the filename to appear when the user closes the upload
form window I would be extremely happy.

Thanks again,
Paul


On May 8, 12:06 pm, Cerebrus <zorg...@sify.com> wrote:

pauld

unread,
May 8, 2008, 4:38:41 PM5/8/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Update 2:
Okay, so I am now guessing that if that var is public then I can
access it from anywhere within the app. So at this point I am asking
how one goes about this in an aspx form, keeping in mind that when you
go between Expression Web and Visual Studio that you cannot do code-
behind.

Thanks again..your reply has gotten my brain working again and I am
very close.

Paul

On May 8, 12:06 pm, Cerebrus <zorg...@sify.com> wrote:

Cerebrus

unread,
May 10, 2008, 3:14:10 AM5/10/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Hi Paul,

Are you opening the page with the FileUpload in a popup window ? If
so, then I'm assuming that your entire upload logic is within the
popup page. I'm also supposing that upon upload, you close the popup
window and refresh the parent page, which should now display the
filename in a textbox. (P.S. : Wouldn't it be more natural to display
the uploaded photo itself in an Image control ?)

If you want to just show the selected filename on the parent page
without posting back to the server, you could do it using the
following simple javascript :

function CloseWin()
{
if (this.opener != null)
{
var srcDoc = this.opener.document;
var txt = srcDoc.getElementById("MyTextBoxClientID");
txt.value =
document.getElementById("MyFileUploadControlClientID").value;
window.close();
}
}

If you can deal with a postback (I would prefer this), your parent
page should refresh and in the Page_Load method, it should check for
the uploaded file, retrieve details and then populate the textbox
control that wil be rendered on the client.
> > > Paul- Hide quoted text -
>
> - Show quoted text -
Reply all
Reply to author
Forward
0 new messages