Hi,
having 1 text box and one button in our asp.net page,then if we enter any folder name in text box (that folder containing images and it might be located in any directory) so we have to display all images in gridview or in datalist in our asp.net page on the basis of that folder name,how is it possible.
plz send asap.
Thanks,
vibhakar singh
Loading

Sanjeeb LenkaRank #301 · 8.3K reputationPosted Jul 18, 2013, 3:04 AM EDT
http://www.aspdotnet-suresh.com/2011/05/how-to-bind-images-from-folder-to.html
Riyaz AkhtarRank #2,275 · 619 reputationPosted Jul 18, 2013, 3:59 AM EDT
aspx:
<asp:GridView ID="GridView1" runat="server">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Image ID="Image1" runat="server" Width="150" Height="100" ImageUrl='<%#Eval("Path")%>'/>
ItemTemplate>
asp:TemplateField>
Columns>
asp:GridView>
CS:
protected void Button1_Click(object sender, EventArgs e)
{
GridView1.DataSource = DirSearch(TextBox1.Text);
GridView1.DataBind();
}
private List<MyImage> DirSearch(string sDir)
{
string path = @"C:\Project\WebApplication1";//ur applcation's physical path
List<MyImage> lstFilesFound = new List<MyImage>();
try
{
foreach (string d in Directory.GetDirectories(path, sDir, SearchOption.AllDirectories))
{
foreach (string f in Directory.GetFiles(d))
{
string virtualFile = f.Replace(path, @"~\");
lstFilesFound.Add(new MyImage() { Path = virtualFile });
}
DirSearch(d);
}
}
catch (System.Exception excpt)
{
Console.WriteLine(excpt.Message);
}
return lstFilesFound;
}
}
public class MyImage
{
public string Path { get; set; }
}