Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing file path/filename back to application 1

Status
Not open for further replies.

sanctified

Programmer
Mar 9, 2006
65
GB
I'm having problems with trying to achieve the following:
I want the user to be able to navigate to a directory to select a file. The path of the file selected should then be passed back into a field so that I can save this in the database.

Questions:
Is there a control I can use for this? I've looked at the HTMLFile control. It allows navigation to the folder/file. How do I save the value back? There is no text attribute for this control or am I missing something?

Any ideas?
 
Use the .NET FileUpload control.

If FileUpload1.HasFile Then ' User selected an existing file
FileUpload1.SaveAs(...) ' To save it
FileUpload1.FileName ' To get the filename
End If
 
where is this control? I can't see it in my toolbox.
Does it allow the user to navigate to a folder like the old file browse to in VB 6?

cheers
 
I've just re-read your post. I don't want to upload the file. I just want a pointer to the file path passed back to my application.
So:
1. The user browes' to the file
2. Selects a file
3. The file path is passed back to the application
 
You don't have to use the upload functionality of the control, just use the dialog part that lets you browse the file system to extract the path you need.
 
thanks tperri.
I'm new to this. Have you got an example?
 
here is the HTML control:
Code:
<INPUT id="MyFile" type="file" name="MyFile" RunAt="Server">
[/code>

and the code to just get the name (I have a button on the page called Submit and this code is in that function)
[code]
string StrFileName = MyFile.PostedFile.FileName;

 
The problem with that method is that it will still actually upload the file to the server even if you don't save it - what happens if the user selects a large file? You don't want them waiting x minutes for the file to upload just to get the path of what they selected.

I'd suggest asking this question in the javascript forum as I imagine there will be a much quicker alternative.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
In fact, in the JavaScript FAQ list, the is an FAQ that may work for you: faq216-5201


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Actually, in my code, my file isnt uploaded unless I use "MyFile.PostedFile.SaveAs(strCompleteFilePath);
 
Yes it is. Even though you don't call the save method, the file is still posted to the server.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top