简体   繁体   English

尝试访问图像文件夹时出现错误?

[英]I got error when i try to acces an image folder?

Iam tried to access an image folder,but when i try to run i got an error Iam尝试访问图像文件夹,但是当我尝试运行时出现错误

"C:/Users/glos/Desktop/My Proj /My Proj/projects//images1' is a physical path, but a virtual path was expected." “ C:/ Users / glos / Desktop / My Proj / My Proj / projects // images1'是物理路径,但是应该使用虚拟路径。”

My code 我的密码

public object post([FromBody]string value)
    {



        var path = HttpContext.Current.Server.MapPath("C:\\Users\\glos\\Desktop\\My Proj\\ projects\\images1");
        var images = Directory.GetFiles(path, "*.png");
        foreach (var image in images)
        {
            System.Console.WriteLine(image);
        }
        return (images);
    }

So how can i create a virtual path ? 那么如何创建虚拟路径

When you know that the file exists in C:\\\\Users\\\\glos\\\\Desktop why do you need Server.MapPath ? 当您知道该文件存在于C:\\\\Users\\\\glos\\\\Desktop为什么需要Server.MapPath - it is needed only when you have a relative path like ~/folder1/folder2 . -仅当您具有~/folder1/folder2类的相对路径时才需要它。

You can also use Directory.GetFiles 您也可以使用Directory.GetFiles

Directory.GetFiles(@"C:\\Users\\glos\\Desktop\\My Proj...");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当我尝试将json发布到webservice时出现错误500 - I got error 500 when I try to post a json to webservice 当我尝试在linklabel单击上显示图像时,出现错误 - When I try to show an image on linklabel click, I get an error 为什么在尝试将数据发布到WebAPI操作时出现404错误? - Why I got an 404 error when I try to post data to a WebAPI action? 当我尝试上传图片时,GDI +中发生一般错误 - A generic error occurrs in GDI+ when I try to upload an image 当我尝试从 mysql 数据库加载图像时,我收到错误“参数无效”,当我尝试从数据库加载图像时 - When I try to load image from mysql database i get error “Parameter is not valid” and when i try to load an image from db 如何从 IDictionary 获取价值? 当我尝试时,出现“不包含方法 TryGetValue”错误 - How can I get value from IDictionary ? When I try I got "does not contain method TryGetValue" error 当尝试比较 linq 中的日期时,我在 .net 中遇到了这个异常 - i got this exception in .net when try to compare date in linq 当我尝试保存图像时,出现错误“ GDI +中发生一般错误”。 - When I try to save an image I get the error “A generic error occurred in GDI+.” 当我尝试将文件夹添加到存档时出现错误:路径太长 - When I try to add a folder to the archive get an error: the path is too long 单击搜索按钮时出错 - i got an error when click search button
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM