我正在尝试从文件夹中获取图像并将其添加到类型图像类型但发现此错误.. 错误1无法将类型'string'隐式转换为'System.Web.UI.WebControls.Image'
Image image;
string[] fileEntries = Directory.GetFiles(@"C:\Users\Hari\Documents\Visual Studio 2012\WebSites\WebSite26\img\");
int numFiles = fileEntries.Length;
for (int picCount = 0; picCount < numFiles; picCount++)
{
image = fileEntries[picCount];
}
答案 0 :(得分:1)
将for循环修改为:
for (int picCount = 0; picCount < numFiles; picCount++)
{
image = new System.Web.UI.WebControls.Image();
// set other image properties
// also i assume that you web root is 'C:\Users\Hari\Documents\Visual Studio 2012\WebSites\WebSite26'
image.ImageUrl = "/img/" + Path.GetFileName(fileEntries[picCount]);
}
无论如何,你的任务目的还不是很清楚。 查看this关于以programmaticaly方式创建图像并将其添加到结果页面的帖子。