[英]Saving images relative to content directory where my site is running in IIS
I want to save images uploaded from a asp mvc page to the content/img/ folder which is relative to where my site is running in IIS. 我想将从ASP MVC页面上传的图像保存到content / img /文件夹,该文件夹相对于我的网站在IIS中运行的位置。 But I don't want to hard code the location on my file system to a Absolute path as this could change easily.
但是我不想将文件系统上的位置硬编码为绝对路径,因为这很容易更改。 This is the code I'm using to save them.
这是我用来保存它们的代码。
public static string SaveCompanyLogoImage(HttpPostedFileBase file)
{
var newFileName = GetNewCompanyLogoFileName(file.FileName);
file.FileName = newFileName;
file.SaveAs(//relative-location-here);
return Path.GetFileNameWithoutExtension(last);
}
Hope this explains my issue! 希望这能解释我的问题!
Thanks for any assistance 感谢您的协助
Use Server.MapPath("~/MyImagesFolder") 使用Server.MapPath(“〜/ MyImagesFolder”)
http://msdn.microsoft.com/es-es/library/system.web.httpserverutility.mappath.aspx http://msdn.microsoft.com/es-es/library/system.web.httpserverutility.mappath.aspx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.