Reputation: 1
I have the following action method , which add an uploaded file to a folder:-
if (ModelState.IsValid)
{
string ADusername = User.Identity.Name.Substring(User.Identity.Name.IndexOf("\\") + 1);
repository.InsertOrUpdateDataCenter(dc, ADusername);
repository.Save();
if (DataCenterfile != null)
{
var fileName = Path.GetFileName(DataCenterfile.FileName);
var path = Path.Combine(Server.MapPath(Url.Content("~/Content/uploads")), dc.ID + ".png");
DataCenterfile.SaveAs(path);
}
return RedirectToAction("Details", new { id = dc.ID });
}
but i am getting the following exception:-
Server Error in '/TMS' Application.
Could not find a part of the path 'C:\inetpub\wwwroot\TMS\Content\uploads\97.png'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\inetpub\wwwroot\TMS\Content\uploads\97.png'.
Source Error:
baring in mind that the above was working well , but after i have published my web application to the IIS i start receiving this error. so can anyone advice how i can solve this ? Thanks
Upvotes: 3
Views: 1822
Reputation: 1
The upload folder is not inside the IIS , so i have to manually Publish it.
Upvotes: -1
Reputation: 9881
I believe what you want to do is to set the "Build Action" for the Content
folder as "Content".
You can do this by selecting the folder in the Solution Explorer, then go under Properties. There you will see the "Build Action" option. Set that to "Content", or maybe "None".
Upvotes: 3