根据下拉选择显示图像

时间:2018-08-02 22:33:41

标签: c# winforms

我的医生清单有一个下拉列表。我想做的是从下拉列表中选择一个名称来显示图像。

我遇到的问题是搜索图像文件夹,并将其与从下拉列表中选择的名称进行比较。

这是我下面尝试做的不起作用的事情:

string imgPath = "\\AccessExpress\ASPCode\OCUpgrade52\images";

if(Directory.Exists(imgPath)){

    string Name = Parameter_SelectName;//Contains the selection from drop down

    if(File.Exists(Path.Combine(imgPath, Name)) )
        Response.Write("true");
    else
        Response.Write("false");
}
else
    Response.Write("false");

出现以下错误: CS1009:无法识别的转义序列

并且很难抓取与要显示的选择匹配的图像

更新:我可以通过以下方法解决此问题(希望这对遇到类似问题的其他人有所帮助):

这是我到目前为止所拥有的:

string imgFolderPath = @"\\AccessExpress\ASPCode\OCUpgrade52\images";

bool folderExists = System.IO.Directory.Exists(imgFolderPath);

if(folderExists){
string urlPath = "http://oc2-reatest/OCUpgrade52/images/";
string imgName= Parameter_SelectName + ".png";
string img = string.Concat(urlPath,imgName);

bool fileExists = System.IO.File.Exists(System.IO.Path.Combine(imgFolderPath, imgName));

if(fileExists)
Response.Write("<img src='" + img + "' />");

else
Response.Write("File Does Not Exists");
}

else
Response.Write("Folder Does Not Exists");

1 个答案:

答案 0 :(得分:0)

我认为只需对您的代码进行少量更改即可。一旦从comboBox或下拉菜单中获取了医生的名字,我想您就是直接将其传递来查找文件是否存在。

尝试一下:-

            string Name = "Parameter_SelectName";
            string path = imgPath + Name + ".jpg"; //jpg being the extention of the pictures
            bool fileExists = System.IO.File.Exists(path);

我希望能解决这个问题。

相关问题