HI All, In my application Im using a textbox and button instead of fileupload control. I would like to know the code for the button so that onclick of button it opens a dialog box and takes the path that has been browsed. Kindly suggest
You can't do this. You have to use the FileUpload control. That's what it is there for as it emits the proper html field for uploading. There is no code that gets this behavior to happen, it's part of the HTML standard and requires the proper elements in
order to work so you can't do this with a textbox and button.
Don't forget to mark useful responses as Answer if they helped you towards a solution.
Probably using some CSS and javascript tricks you can achieve this...again I am not sure....but why would you want to do this??? When you have asp.net fileuplod control and infact html file type control, why you want to reinvent the wheel??
but still you want to give a try....put up a html file type control and make it hidden, then on button client click stimulate hidden controls click event using javascript...having said that I dont know whether you can post the file to server or not,...give
it a try and let me know...
In my application, when user selects the file path using file upload control and clicks on some button, after the page loads I want to retain and display the file path in the fileupload control text box which user has selected which Im not able to get that.
So I was checking the other way. If you could suggest me how to retain value into the textbox after page load then that satisfies my requirement.
In my application, when user selects the file path using file upload control and clicks on some button, after the page loads I want to retain and display the file path in the fileupload control text box which user has selected which Im not able to get that.
So I was checking the other way. If you could suggest me how to retain value into the textbox after page load then that satisfies my requirement.
Thanks
Actually, you can not get the full path of the uploaded file through FileUpload.PostedFile.FileName from server. It just a file name. this feature has been disabled due to security reasons on most browsers. Any website should not need path
of a file stored in client's systems because that gives the directory structure and may expose other important things to website owner.
If you want to upload files without using the FileUpload server control, you can use input tag instead of FileUpload control.Pleaselook at the
followingsimple
example:
frndz293
Member
6 Points
31 Posts
Code for FileUpload control in vb.net
Apr 17, 2012 01:25 PM|LINK
HI All, In my application Im using a textbox and button instead of fileupload control. I would like to know the code for the button so that onclick of button it opens a dialog box and takes the path that has been browsed. Kindly suggest
markfitzme
Star
14333 Points
2217 Posts
Re: Code for FileUpload control in vb.net
Apr 17, 2012 01:44 PM|LINK
You can't do this. You have to use the FileUpload control. That's what it is there for as it emits the proper html field for uploading. There is no code that gets this behavior to happen, it's part of the HTML standard and requires the proper elements in order to work so you can't do this with a textbox and button.
Sparkers
Contributor
2086 Points
470 Posts
Re: Code for FileUpload control in vb.net
Apr 17, 2012 01:49 PM|LINK
This should help you,
http://www.4guysfromrolla.com/webtech/091201-1.shtml
ramiramilu
All-Star
95275 Points
14072 Posts
Re: Code for FileUpload control in vb.net
Apr 17, 2012 02:24 PM|LINK
Probably using some CSS and javascript tricks you can achieve this...again I am not sure....but why would you want to do this??? When you have asp.net fileuplod control and infact html file type control, why you want to reinvent the wheel??
but still you want to give a try....put up a html file type control and make it hidden, then on button client click stimulate hidden controls click event using javascript...having said that I dont know whether you can post the file to server or not,...give it a try and let me know...
Thanks,
JumpStart
John Bhatt
Member
164 Points
29 Posts
Re: Code for FileUpload control in vb.net
Apr 17, 2012 02:31 PM|LINK
While you have FileUpload Tool available and you can use that. Why do you want to waste your time?
Shoaib Rashi...
Member
291 Points
116 Posts
Re: Code for FileUpload control in vb.net
Apr 17, 2012 02:32 PM|LINK
see the link below
http://www.c-sharpcorner.com/UploadFile/mahesh/FileUpload10092005172118PM/FileUpload.aspx
frndz293
Member
6 Points
31 Posts
Re: Code for FileUpload control in vb.net
Apr 19, 2012 10:29 AM|LINK
In my application, when user selects the file path using file upload control and clicks on some button, after the page loads I want to retain and display the file path in the fileupload control text box which user has selected which Im not able to get that. So I was checking the other way. If you could suggest me how to retain value into the textbox after page load then that satisfies my requirement.
Thanks
Sparkers
Contributor
2086 Points
470 Posts
Re: Code for FileUpload control in vb.net
Apr 19, 2012 01:05 PM|LINK
You can actually take a label or textbox whatever you want and just populate the value of the FileUpload.
You can do this when the FileUpload Control is posting the data to the server.
use..
System.IO.Path.GetDirectoryName(Server.MapPath(FileUpload1.PostedFile.FileName));
YunJiang
Participant
1124 Points
122 Posts
Re: Code for FileUpload control in vb.net
Apr 28, 2012 07:00 AM|LINK
Actually, you can not get the full path of the uploaded file through FileUpload.PostedFile.FileName from server. It just a file name. this feature has been disabled due to security reasons on most browsers. Any website should not need path of a file stored in client's systems because that gives the directory structure and may expose other important things to website owner.
If you want to upload files without using the FileUpload server control, you can use input tag instead of FileUpload control.Please look at the following simple example:
protected void btnUploadClick(object sender, EventArgs e) { HttpPostedFile file = Request.Files["myFile"]; if (file != null && file.ContentLength>0) { string fname = Path.GetFileName(file.FileName); file.SaveAs(Server.MapPath(Path.Combine("~/App_Data/", fname))); } }