Click here to Skip to main content
15,891,708 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a web based application in that application user can login after login it will upload the files.but i can not save the file on my server i just read the data and data will be saved in the database how i get the user directory path where the file exits.

What I have tried:

string path = HttpContext.Current.Server.MapPath("");
Posted
Updated 8-Aug-16 16:18pm

When a user uploads a file it doesn't go to any directory. It's still sitting in the Request object, in the Files collection. It's up to you to get the content and save the files somewhere appropriate.

See this[^] for an example.
 
Share this answer
 
I see you are dealing with MVC6 (as it shown in the question tag). Server.MapPath may not work. You need to deal with IApplicationEnvironment interface, namespace Microsoft.Extensions.PlatformAbstractions to get the server path. Something like
C#
private readonly IApplicationEnvironment _appEnvironment;
public HomeController(IApplicationEnvironment appEnvironment)
{
    _appEnvironment = appEnvironment;
}

public IActionResult Index()
{
    var rootPath = _appEnvironment.ApplicationBasePath;
    return View();
}

For more look here. Environment Variables in ASP.NET Core Apps[^]
 
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