Click here to Skip to main content
15,903,388 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i want to upload a file to folder 'Documents' which is in root directory.
below code does'nt work,but file is uploaded to physical path

C#
protected void Button1_Click(object sender, EventArgs e)
        {
            string filename = Path.GetFileName(FileUpload1.FileName);
            FileUpload1.PostedFile.SaveAs(Server.MapPath("~/Documents/") + filename);
        }


no update panel is used

please help me with this.
Posted

1 solution

What physical path? It is a 'physical' file so must be stored in a physical path!
MSDN:
The MapPath method maps the specified relative or virtual path to the corresponding physical directory on the server.

So it is all right...The SaveAs method will save the file in the physical path where the "~/Documents" virtual path points...
 
Share this answer
 
Comments
sunnykvinod 7-Jul-15 3:28am    
but it is not working i cant see any file in Documents folder after upload and no exception being raised
Kornfeld Eliyahu Peter 7-Jul-15 3:43am    
How do you look for them?
What does 'not working' means? There is some error? The file saved on different path?
sunnykvinod 8-Jul-15 9:08am    
its working now the mistake i made is i have stored the file path in database incorrectly.

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