Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/30.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
C# ASP.NET-相对于文件夹导航_C#_Asp.net_Path_Directory - Fatal编程技术网

C# ASP.NET-相对于文件夹导航

C# ASP.NET-相对于文件夹导航,c#,asp.net,path,directory,C#,Asp.net,Path,Directory,“好久不见ASP.NET”和很多已经被遗忘。当我试图查找文件夹images时,我似乎找不到它,除非我使用绝对路径(这不是首选路径),否则我将如何执行此操作 我的文件夹结构是这样的 + C +--+ project +--+ controls +--+ slideshow +--- slideshow.ascx +--+ images +--- 1.png +--- 2.png 在我的slide

“好久不见ASP.NET”和很多已经被遗忘。当我试图查找文件夹
images
时,我似乎找不到它,除非我使用绝对路径(这不是首选路径),否则我将如何执行此操作

我的文件夹结构是这样的

+ C
+--+ project
   +--+ controls
      +--+ slideshow
         +--- slideshow.ascx
         +--+ images
            +--- 1.png
            +--- 2.png
在我的slideshow.ascx.cs文件中,我有以下内容:

       string imagePath = @"C:\project\controls\slideshow\images";

            if (Directory.Exists(imagePath))
            {
                try
                {
                    string[] files = Directory.GetFiles(imagePath);
                    List<CarParts24.Source._2ModelEntity.Image> images = new List<Source._2ModelEntity.Image>();

                    foreach (string image in files)
                    {
                        images.Add(new CarParts24.Source._2ModelEntity.Image(image));
                    }

                    litSlideshow.Text = "<span id=\"slideshow-urls\">" + JsonConvert.SerializeObject(images) + "</span>";
                }
                catch (Exception ex)
                {
                    Console.WriteLine(new DateTime() + " - ERROR: " + ex);
                }
            }
string imagePath=@“C:\project\controls\slideshow\images”;
if(Directory.Exists(imagePath))
{
尝试
{
string[]files=Directory.GetFiles(imagePath);
列表图像=新列表();
foreach(文件中的字符串图像)
{
images.Add(新CarParts24.Source.\u 2 modelenty.Image(图像));
}
litSlideshow.Text=“+JsonConvert.SerializeObject(图像)+”;
}
捕获(例外情况除外)
{
Console.WriteLine(new DateTime()+“-错误:”+ex);
}
}

这是可行的,但如何将
imagePath
更改为相对路径?

假设您的网站指向C:\project

Server.MapPath("~") + @"\controls\slideshow\images"