Click here to Skip to main content
14,029,830 members
Rate this:
Please Sign up or sign in to vote.
Could not save an uploaded file in server while its working fine in local. Thinking that filesaving path is an issue with server.mappath. suggest me where I've gone wrong.. Here is what I did and its working in local. 

What I have tried:

if (file.ContentLength > 0)
              var fileName = Path.GetFileName(file.FileName);
              var location = Path.Combine(Server.MapPath("~/FormUploads"), fileName);
Updated 6-Feb-19 4:17am
Richard MacCutchan 6-Feb-19 7:12am
What does the variable 'location' contain when you try the save?
Member 13794985 6-Feb-19 7:22am
its getting full path as: D:\NewFolder\SolutionName\ProjectName\FormUploads\background.jpg

tried to give path in different ways, but couldn't find a way to send the saveas path which is not from root directory. help me to figure this out.
F-ES Sitecore 6-Feb-19 7:43am
This is a very well documented task so google for "c# mvc upload and save file" and you'll find lots of examples. If you're getting any error messages then post what they are.
Richard MacCutchan 6-Feb-19 8:07am
Is that a valid path with access permissions for the server? What is the actual error you receive when you run the code?

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

I posted a tip about this a number of years ago:

Resolving Paths in a Multi-Folder WebSite[^]

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Cookies | Terms of Service
Web05 | 2.8.190419.4 | Last Updated 6 Feb 2019
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100