如何仅获取图像名称并在全路径图像下的图像中显示 [英] how to get only image name and display in under images from full path image
问题描述
请查看下面的源代码以得到清晰的说明.........
*********************
我已经编写了这段代码,但是在这里获得了图像的完整路径
检查我的代码之一,让我告诉我这里应该怎么做..............
CS代码::::
Please check out below source code for clear clarification ..................
*********************
I have wrote this code but here getting full path of the image
check one of my code let me tell what should i wrong here..............
cs code ::::
protected void btnsearch_Click(object sender, EventArgs e)
{
string path = HttpContext.Current.Request.PhysicalApplicationPath + @"\gallery\" + ddl1.SelectedItem.Text.ToString()+
'/'+ddl2.SelectedItem.Text.ToString()+'/'+ddl3.SelectedItem.Text.ToString()+'/'+ddl4.SelectedItem.Text.ToString()+'/'+ddl5.SelectedItem.Text.ToString();
string[] files = System.IO.Directory.GetFiles(path, "*", SearchOption.AllDirectories);
IList<hi> imageFileList = new List<hi>();
foreach (string strFileName in files)
{
imageFileList.Add(new hi { filename = ResolveUrl (strFileName.Replace (Server.MapPath("k"), "~")) });
Response.Write(k+"<br"> }
DataList1.DataSource = imageFileList;
DataList1.DataBind();
asp.code ::
asp.code::
<asp:DataList ID="DataList1" runat="server" RepeatColumns="3" CellPadding="4"
RepeatDirection="Horizontal">
<ItemTemplate>
<asp:Image ID="imgPicture" runat="server" ImageUrl='<%#Eval("filename") %>' width="50px" Height="50px"/>
<br />
<asp:HyperLink ID="HyperLink1" Text='<%# Bind("filename") %>' NavigateUrl='<%# Bind("filename") %>' runat="server"/>
</td>
</ItemTemplate>
</asp:DataList>
图标设计, youtube到mp3
游戏, youtube到mp3
iphone应用程序设计, youtube到mp3
iphone图标设计, youtube到mp3
iphone图标设计器, youtube到mp3
icon design, youtube to mp3
games, youtube to mp3
iphone app design, youtube to mp3
iphone icon design, youtube to mp3
iphone icon designer, youtube to mp3
推荐答案
首先,您不需要在文本属性上使用ToString-如果它们已经是字符串,则使用ToString是只是浪费内存,处理时间和打字.使用String.Format代替串联也将更加明显(高效):
Firstly, you don''t need to use ToString on Text properties - if they are already a string, then using ToString is just a waste of memory, processing time and typing. It would also be more obvious (and efficient) to use String.Format instead of concatenation:
string path = string.Format(@"{0}\gallery\{1}\{2}\{3}\{4}\{5}",
HttpContext.Current.Request.PhysicalApplicationPath,
ddl1.SelectedItem.Text,
ddl2.SelectedItem.Text,
ddl3.SelectedItem.Text,
ddl4.SelectedItem.Text,
ddl5.SelectedItem.Text);
然后,查看您的代码以执行输出:
Then, look at your code to do the output:
imageFileList.Add(new hi { filename = ResolveUrl (strFileName.Replace (Server.MapPath("k"), "~")) });
Response.Write(k+"<br"> }
什么是"k"?为什么在MapPath中将其用作字符串,在Response.write中将其用作变量?
什么是hi
类?它为DataList提供了什么?
尝试将Add方法行分解为各个组成部分,并使用调试器检查每个组件的确切操作,因为我不禁会认为您在某个地方有些困惑.
What is "k"? Why do you use it as a string in the MapPath, and a variable in the Response.write?
What is the hi
class? What does it provide to the DataList?
Try breaking the Add method line into the various component parts, and use the debugger to examine exactly what each is doing, because I can''t help thinking you are a bit confused in there somewhere.
这篇关于如何仅获取图像名称并在全路径图像下的图像中显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!