to get full file location from file upload control

Posted by Amritha444 under ASP.NET on 4/12/2011 | Points: 10 | Views : 81542 | Status : [Member] | Replies : 6
Hi all

Im using fileupload control and i want the location comes in the fileupload control.But where i get only filename

For example
My file may be in C:/myfolder/hi.txt

i want this location instead im getting only file name

string filename1 = Path.GetFileName(FileUpload1.FileName);
string ls_nm = HiddenField1.Value;
string path = Path.GetDirectoryName(FileUpload1.PostedFile.FileName);
string toatal = FileUpload1.PostedFile.FileName;

All these methods returns only that filename

how to get exact location??

thanks in Advance




Responses

Posted by: Prabhakar on: 4/12/2011 [Member] [MVP] Starter | Points: 25

Up
0
Down
Hi amritha


write this line on ur code for full path . . use it Server.MapPath

FileUpload1.SaveAs(Server.MapPath("download/" + FileUpload1.FileName));

and u want to dir info so write this . .

DirectoryInfo dirinfo = new DirectoryInfo(Server.MapPath("IMG/"));

Best Regard's
Prabhakar

Amritha444, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: NDebata on: 4/12/2011 [Member] Starter | Points: 25

Up
0
Down
Hi

If you want the file location in client machine

You can use

string fileLoacation=FileUpload1.PostedFile.FileName;

Thanks,
Debata

Amritha444, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Fenchkarthi on: 3/22/2012 [Member] Starter | Points: 25

Up
0
Down
Hi All,

string fileLoacation=FileUpload1.PostedFile.FileName;
Above code will not work in other browser like firefox. it will work only in IE

You can't get full path of the file.
For security purposes, the browser will never post the full file's path.

Try to use below code in java script.
lbltext.Text = FileUpload1.PostedFile.FileName

reference: http://weblogs.asp.net/ashicmahtab/archive/2009/05/20/fileupload-control-doesn-t-give-full-path-help.aspx

Regards,
fench

Amritha444, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Patel28rajendra on: 3/22/2012 [Member] Starter | Points: 25

Up
0
Down
Hi

see this link


http://www.codeproject.com/Questions/107510/how-to-find-absolute-path-of-image

R D Patel

Amritha444, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vinay13mar on: 10/14/2012 [Member] Starter | Points: 25
Posted by: Feelixdeleo on: 2/26/2014 [Member] Starter | Points: 25

Up
0
Down
the user may also be required to go to
control panel
internet options
security(tab)
custom level(btn)
go a little more than 1/2 down and find
allow full path to be given (or something similar)
radio button ENABLE

I hadn't seen any reference to this


Amritha444, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response