Reputation: 290
I have implement the following code to upload a file. The file is upload to the location ("../App_Data/uploads") but it does not show up in the project. I have to include the file manually in the project. Why is the file not showing up?
public ActionResult ChangeSetting(SettingViewModel setting)
{
string userId = User.Identity.GetUserId();
ApplicationUser currentUser = this._appUserRepo.Find(e => e.Id.Equals(userId)).FirstOrDefault();
if (setting.PictureUrl != null)
{
if (setting.PictureUrl.ContentLength > 0)
{
string fileName = Path.GetFileName(setting.PictureUrl.FileName);
if (fileName != null)
{
string path = Path.Combine(Server.MapPath("../App_Data/uploads"), fileName);
setting.PictureUrl.SaveAs(path);
if (currentUser != null)
{
currentUser.PictureUrl = path;
currentUser.PictureSmalUrl = path;
currentUser.PictureBigUrl = path;
}
}
}
}
if (setting.FirstName != null)
{
if (currentUser != null) currentUser.FirstName = setting.FirstName;
}
_appUserRepo.Update(currentUser);
return RedirectToAction("index", "Admin");
}
Upvotes: 1
Views: 1772
Reputation: 1038810
Why is the file not showing up?
Because that's how Visual Studio projects work - only files that you manually include into the project are shown in the solution explorer. Files that get added dynamically to folders afterwards by eternal processes do not show up in Visual Studio (unless you manually include them and make them part of the solution). But that's probably not something you should be worried about. The files uploaded by users won't automagically appear in your Visual Studio project. The important thing is that they are present at the expected location and that your web application is capable of accessing them at runtime. Just open the physical location of the folder in Windows Explorer to confirm that your code is working as expected.
Upvotes: 7