Click here to Skip to main content
15,867,488 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Good day, i want to get the fullpath to a file on my system when i submit a form data.
this is my view where the file input tag is located
C#
<input name="ad1file" type="file" id="passport" required>


this is my controller
C#
string path = Request.Files["ad1file"].FileName;
               FormData fd = new FormData
               {
                   ad1file = Path.GetFullPath(path)
               };


the functions GetFileName() returns the file name and GetFullPath() returns the absolute path, both of which isn't pointing me to the file.
and when i displayed it using this, i don't see any image
C#
<img name="ad1pass" src="@Model.ad1file" alt="passport" width="150" height="150">

Thanks for your assistance
Posted
Comments
Kevin Marois 21-Jan-16 14:25pm    
What path is Path.GetFullPath(path) returning?
EasyHero 21-Jan-16 14:32pm    
path contains the file name. string path = Request.Files["ad1file"].FileName; its d first line of my controller function
Kevin Marois 21-Jan-16 14:42pm    
What I asking is.. If Path.GetFullPath(path)
doesn't give you the actual path, then what IS being returned? A relative path? I ask because Path.GetFullPath should return the absolute path.
EasyHero 21-Jan-16 14:47pm    
yes, its returning the absolute path. still doesn't show the image in the <img/>
it returns this C:\Program Files (x86)\IIS Express\166875_172708726105688_7981605_n.jpg which isn't the location of the image on my harddrive
Kevin Marois 21-Jan-16 14:51pm    
Ok. You said it isn't pointing you to the file, so the file's not there? Why is it incorrect?

1 solution

This appears to be ASP.NET code which runs entirely server side. If you're expecting to get a full file path sent by the client it's not going to happen. The server will not get access to, nor should it ever care about, what path the file came from on the client.
 
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