List 如何测试图像';s.根据列表绘制格式<;字符串>;Web.Config中的扩展名?
我想把允许的图像上传扩展放在web.config中,以便以后修改。我现在在这里的工作,但是硬编码List 如何测试图像';s.根据列表绘制格式<;字符串>;Web.Config中的扩展名?,list,List,我想把允许的图像上传扩展放在web.config中,以便以后修改。我现在在这里的工作,但是硬编码 if (!img.RawFormat.Equals(ImageFormat.Png) && !img.RawFormat.Equals(ImageFormat.Gif) && !img.RawFormat.Equals(ImageFormat.Jpeg)
if (!img.RawFormat.Equals(ImageFormat.Png)
&& !img.RawFormat.Equals(ImageFormat.Gif)
&& !img.RawFormat.Equals(ImageFormat.Jpeg)
&& !img.RawFormat.Equals(ImageFormat.Bmp))
{
ViewBag.Message = "Wrong Image Type. Please use an image one with the following extenstions:<br /><b>.jpeg, .gif, .png, or .bmp</b>";
return View(location);
}
if(!img.RawFormat.Equals(ImageFormat.Png)
&&!img.RawFormat.Equals(ImageFormat.Gif)
&&!img.RawFormat.Equals(ImageFormat.Jpeg)
&&!img.RawFormat.Equals(ImageFormat.Bmp))
{
ViewBag.Message=“图像类型错误。请使用具有以下扩展名的图像类型:
.jpeg、.gif、.png或.bmp”;
返回视图(位置);
}
这是我一直在尝试的,但我需要传递一个ImageFormat而不是字符串。。。我如何做到这一点
bool isAcceptedType = false;
List<string> AcceptedImageTypes = System.Configuration.ConfigurationManager.AppSettings["AcceptedImageTypes"].Split('|').ToList();
foreach (string s in AcceptedImageTypes)
{
if (img.RawFormat.Equals(s))
{
isAcceptedType = true;
}
}
if (!isAcceptedType)
{
ViewBag.Message = "Wrong Image Type. Please use an image one with the following extenstions:<br /><b>.jpeg, .gif, .png, or .bmp</b>";
return View(location);
}
bool isAcceptedType=false;
List AcceptedImageTypes=System.Configuration.ConfigurationManager.AppSettings[“AcceptedImageTypes”].Split(“|”).ToList();
foreach(AcceptedImageTypes中的字符串s)
{
if(img.RawFormat.Equals)
{
isAcceptedType=true;
}
}
如果(!isAcceptedType)
{
ViewBag.Message=“图像类型错误。请使用具有以下扩展名的图像类型:
.jpeg、.gif、.png或.bmp”;
返回视图(位置);
}
我在这页上找到了答案