Click here to Skip to main content
16,016,022 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
when i use the code in C#
C#
string fullPath = Server.MapPath(fileupload1.PostedFile.FileName);

i want the result as

C:\Documents and Settings\rajkumar.t\Desktop\vCard.vcf

but i got result as

C:\Documents and Settings\rajkumar.t\Desktop\CRM\form\vCard.vcf

CRM/form is my project the fileupload control is here.
what i have to enhance?
Posted
Updated 22-Nov-11 22:50pm
v2

try

Server.MapPath(FileUpload1.FileName);

Hope it helps.
 
Share this answer
 
Comments
tssrajkumar@gmail.com 23-Nov-11 5:02am    
thanq for responding my question, but the same only comes as the result
You can't, reliably. Security forbids this, as it would give information (albeit indirectly) about the client hardware.
You can't use it anyway - there is no way to reload it to the original location, as the client browser has control over where it goes, not you.
IE will return a path (sort of), FF will return only the name, and so on.
 
Share this answer
 
Comments
tssrajkumar@gmail.com 23-Nov-11 5:05am    
so what can i do for this, is there any other way to do this, i need the path which i want to browse and select, can u help?
OriginalGriff 23-Nov-11 5:23am    
You can't do it. You have no control over the client browser - you cannot tell it where to look, it will always look in the last place the user uploaded a file from. Anything which allowed you to set such values would effectively give you limited access to the registry (assuming it is a PC) which would be a very, very bad idea from a security point of view.
What are you trying to do, that you think you need this?
tssrajkumar@gmail.com 23-Nov-11 6:48am    
the idea behind me to do is, a .vcf file which will be selected by a user, the content of the file should be read by File.ReadAllText() function, then every value read by function from that file wants to save in the database. is there any way to do this functionality?.
Timberbird 23-Nov-11 7:29am    
After users selects the file and submits it on the server, you already have that file contents and therefore there's no need to save it on disk - it can be written to database directly
you have to mannualy remove last folder names from your path string.

the article describes the solution,

http://www.dotnetheaven.com/uploadfile/prathore/how-to-find-last-index-of-the-string-in-Asp-Net-using-C-Sharp/[^]
 
Share this answer
 
Are you trying to get local file name on the client or build a file name to store uploaded file on server?

The first is hard to achieve - actually, impossible in most cases. It is browser dependent.

As to the second: Server.MapPath() method maps virtual or relative path to a path on server. fileupload1.PostedFile.FileName contains the name of the loaded file.
According to the code, you are trying to map file name on the client (in most cases without path) to the path on server. And documentation on MapPath method[^] says that when relative path doesn't start with a slash, you'll receive a path "relative to the directory of the .asp file being processed" - i.e. your web form directory.

To resolve the problem you can store absolute path to your upload folder in custom settings or get web application root path and add fixed relative path. Besides, avoid using FilePath directly - see this link[^], for example
 
Share this answer
 
it's may be help you..
Application.StartupPath
 
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