Retrieving the file name

foz

Freshman
Joined
Mar 2, 2004
Messages
34
Location
Ireland
What I am wanting to to:

I have a web application, and in this application I want to allow the users choose what database queries are going to be run against. What I'd planned to do was use a <input type="file" id="filename" runat="server"><br><asp:button id="btnUpload" runat="server" Text="Upload" onClick="runQuery">. For testing purposes the runQuery fn is just setting the text value of a label to filename.value.tostring().

Problem:

This works fine for files that are approx 4mb and lower but doesnt work for files bigger than this. I think that it's trying to upload the whole file, when all i need is the file name.

Is there another way around this?

Cheers,

foz
 
By using the <input type=file> you're telling the page to upload the file. unfortunately that's the only way you can do it.

If the databases are in a common place on the server, you could always go and get a list of them, and give the user a dropdown list to choose from. If they're in multiple directories, you could start them out in the root and then let them click through on web pages.

It may mean a few more clicks, but you won't have the databases being sent to the server with the request when you don't need it.
 
wayneph said:
By using the <input type=file> you're telling the page to upload the file. unfortunately that's the only way you can do it.

If the databases are in a common place on the server, you could always go and get a list of them, and give the user a dropdown list to choose from. If they're in multiple directories, you could start them out in the root and then let them click through on web pages.

It may mean a few more clicks, but you won't have the databases being sent to the server with the request when you don't need it.

cheers mate,

another user has suggested the follow and i think that it's what i'm going to use.

##################################################

1. Move the input type="file" outside of the form tags
2. Create a hidden field called tmpFilename
3. Modify the input type="submit" as follows:
Code:
<input type="submit" id="submit" onClick="putFilename()" onserverclick="submit">
4. putFilename is a cs-javascript that sets the value of the hidden field to the value of the input type="file"
5. in the server side submit fn I can access the file name with Page.Request.Form["tmpFilename"].

##################################################

Not the slickest of code, but it works for me :D
 
I didn't realize that JavaScript would allow you to pull the file name out of a <input type=file> field. That would allow you to still use a Browse button, which is always nice.
 
Back
Top