Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a Fileupload control in my Web page,I am taking an input file from user

I want to get the path of the input file,I am not saving(ie uploading the file)

How can i get the path of the file without uploading the file from fileupload?

I have tried
C#
Server.MapPath(FileUpload.FileName);


but it is returning path with filename i want without file name
Posted
Updated 27-Jul-11 6:24am
v3

u can try to get upload file path use this code.
ohhh please if your application is web application then u must
postback your web page after upload a file.

C#
if (fUpload.PostedFile != null)
{                                                                                 
    HttpPostedFile ciFile = fUpload.PostedFile;                            
    string sFileName = System.IO.Path.GetFileName(ciFile.FileName);
    string sFile = System.IO.Path.GetFileNameWithoutExtension(sFileName);
    string sExtension = System.IO.Path.GetExtension(sFileName);            
}
 
Share this answer
 
v2
Hi,

Since the FileUpload Control is just a simple <input type="file" />, there is no possibility to get the file path without uploading the file (also the upload should not change this behaviour?).

Also most of the modern browsers will block the access to the full-path access by JavaScript. But perhaps you have some luck on your systems.

Here is a starting point:
http://rattomago.wordpress.com/2009/02/18/accessing-filepath-in-html-input-element-via-javascript/[^]

(this is only usable in a intranet environment where you can update the browser settings to allow the full-path access).

Hope this helps.

Best regards and happy coding,
Stops
 
Share this answer
 
Server.MapPath(FileUpload.FileName) wont help with anything. You cant view the path of the file on the users computer. This is a security feature and is left out on purpose to protect users.
 
Share this answer
 
You can't get it without uploading, and you often can't get it WITH uploading. The other thing to remember is, if you had a path on the client machine, there is not a thing you could do with it, you'd have no access to it.
 
Share this answer
 
You cannot access the users desktop from the brower. It is a security risk. The browser will allow you to read files to upload only. The only way you could achieve this is using flash or a browser plugin that is not constrained but the browsers security sandbox.

Have a look at this link[^] maybe you can find something benefical.
 
Share this answer
 
import the namespace system.io

then try the like this

strpath = path.getfilename(fileupload.postedfile.filename).tostring();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900