c# - Image server path ASP.NET Including controller and method -
i having problem deleting image in asp.net mvc 5 application. creating user management module of application requires images/photos of staff uploaded. however, since profile should editable, image should made possible deleted. when try delete image, find difficult locating correct path of image. when use
var filetodelete = path.combine(server.mappath("~content/photos/people/"),updatedstaff.photo); system.io.file.delete(filetodelete);
or
`var filetodelete = server.mappath("~content/photos/people/"+updatedstaff.photo); system.io.file.delete(filetodelete);`
the path returned image wrong in that, contains controller , method in path , cannot delete image.
this error message get:
could not find part of path 'c:\users\josh\documents\visual studio 2015\projects\eduplus\eduplus\staffmembers\edit\~content\photos\people\de1e1cf0-d.jpg'
"staffmembers" controller , "edit" method
please appreciate assistance figure out problem.
thank you
~/
need use before content
, not ~
.
this should work fine.
var filetodelete = path.combine(server.mappath("~/content/photos/people"), updatedstaff.photo);
Comments
Post a Comment