Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
List 如何测试图像';s.根据列表绘制格式<;字符串>;Web.Config中的扩展名?_List - Fatal编程技术网

List 如何测试图像';s.根据列表绘制格式<;字符串>;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)

我想把允许的图像上传扩展放在web.config中,以便以后修改。我现在在这里的工作,但是硬编码

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”; 返回视图(位置); }
我在这页上找到了答案