Nate Pet
Nate Pet

Reputation: 46312

Asp.net uploading file

I have a FileLoad controller as such:

     <asp:FileUpload ID="FileUpload1" runat="server" />

What I like to do is to upload the file to the /images/logos folder on the server once the user selects the gif image:

     string uploadFolder = Server.MapPath("/images/logos/");

     string uploadfile = uploadFolder + "Image1" + ".gif";
     FileUpload1.SaveAs(uploadfile); 

When I look at the value of uploadfile it starts with C:....

I believe it should be something like /images/logos/Image1.gif as when it completes, nothing is in the images/logos folder. Note that I do not get any errors.

What am I doing wrong.

Upvotes: 0

Views: 282

Answers (2)

nerdybeardo
nerdybeardo

Reputation: 4685

Server.MapPath gives you the absolute path on the server based on the relative path you provide.

http://msdn.microsoft.com/en-us/library/ms524632%28v=vs.90%29.aspx

Upvotes: 0

Jack Hughes
Jack Hughes

Reputation: 206

Server.MapPath("/images/logos/") // Will map to the wwwroot folder
Server.MapPath("~/images/logos/") // Will map to the application folder

Upvotes: 1

Related Questions