【发布时间】:2016-10-05 23:04:57
【问题描述】:
“好久不见 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);
}
}
这可行,但我如何将imagePath 更改为相对路径?
【问题讨论】: