显示图片时 不能够获取正确 的 路径if((System.IO.Path.GetExtension(entry.Name)=="gif") || (System.IO.Path.GetExtension(entry.Name)

fanxiangqin 2003-10-20 02:41:24
显示图片时 不能够获取正确 的 路径if((System.IO.Path.GetExtension(entry.Name)=="gif") || (System.IO.Path.GetExtension(entry.Name)=="jpg"))总是检测几个根目录下的 bin 等,不能 检测 images 目录 ,和根目录下的文件

void ListImages()
{
//initialize control
imageOutput.Controls.Clear();
string strUploadPath = Request.QueryString["UploadPath"];
string strDirectory = Server.MapPath("~/"+ strUploadPath);
DirectoryInfo dir = new DirectoryInfo( strDirectory );
foreach ( FileSystemInfo entry in dir.GetFileSystemInfos() )
{
if((System.IO.Path.GetExtension(entry.Name)=="gif") || (System.IO.Path.GetExtension(entry.Name)=="jpg"))
{
HtmlImage image1 = new HtmlImage();
image1.Src = "/" + strUploadPath + "/" + entry.Name;
image1.Height=100;
image1.Border=1;
image1.Attributes.Add("onclick","javascript:window.returnValue ='" + strUploadPath + "/" + entry.Name +"';" +" window.close();");
imageOutput.Controls.Add(image1);
}
}
}
...全文
89 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
cityhunter172 2003-10-21
  • 打赏
  • 举报
回复
this.Image1.ImageUrl=Page.ResolveUrl(this.TextBox1.Text+"\\"+up[up.Length-1]);
cityhunter172 2003-10-21
  • 打赏
  • 举报
回复
我已在短消息回答你的问题了

注意查收,服务器只保留一个星期
menuvb 2003-10-21
  • 打赏
  • 举报
回复
这样,比如你将全部图像放到image 中,
dim filename as string=server.mappath(".") & "/image" & "你图像的名称,包括后缀名"

再举一下,比如数据库你放在db目录下,
dim filename as string=server.mappath("db/database.mdb")
elite2018 2003-10-20
  • 打赏
  • 举报
回复
use break Point to show what path do you relly locate
Abac 2003-10-20
  • 打赏
  • 举报
回复
Server.MapPath指的是和当前页面相对的位置,估计你要使用类似
Server.MapPath("/images/aa.gif")
或者Server.MapPath("../images/aa.gif")
或Server.MapPath("images/aa.gif")
来指向正确的目录
fanxiangqin 2003-10-20
  • 打赏
  • 举报
回复
不行
lbzq 2003-10-20
  • 打赏
  • 举报
回复
将图片放入工程目录下的image中,调用的时候用
server.mappath(".")\image\aaa.gif
qianblue 2003-10-20
  • 打赏
  • 举报
回复
所有的"/"用@"/"替换就可以了

62,025

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧