Last post Jun 26, 2017 02:29 AM by JBetancourt
Jun 25, 2017 09:39 PM|BitLost|LINK
I have a form accepting inputs and allowing an upload for a file.
In code I have:
public class ClientsController : Controller
private readonly Eva804Context _context;
static public IHostingEnvironment _environment;
public ClientsController(IHostingEnvironment environment)
_environment = environment;
................ blah, blah, blah...................Then
model.ShentonAcc = viewModel.ShentonAcc;
model.Suburb = viewModel.Suburb;
if(fmodel != null)
fmodel.DocTypeID = fmodel.DocTypeID;
var uploads = Path.Combine(_environment.WebRootPath, "FileName");
foreach (var file in FileName)
if (file.Length > 0)
using (var fileStream = new FileStream(Path.Combine(uploads, file.FileName), FileMode.Create))
fmodel.FileName = uploads;
After mucking about I realise the issue is with Path.Combine(_environment.WebRootPath as the examples I have all declare IHostingEnvironment as a DI. This conflicts with the existing DI.
All okay sort of, until I try and find a replacement for the Path.Combine that doesn't require DI. What should I be looking for? Is there a work around for this?
Jun 26, 2017 02:18 AM|AngelinaJolie|LINK
Based on your code , I guess what you are really want is _environment.WebRootPath at controller;
if so, please refer to my working code for it:
string currentpath = Directory.GetCurrentDirectory(); //currentpath:"C:\\Users\\v-tiguo\\Source\\Repos2017\\ContosoUniversity\\src\\ContosoUniversity"
Jun 26, 2017 02:29 AM|JBetancourt|LINK
why would you need a "...a replacement for the Path.Combine that doesn't require DI"
could you explain your use case