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
Riyaz AkhtarPosted Jul 18, 2013, 7:59 AM
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; }
}
Sanjeeb LenkaPosted Jul 18, 2013, 7:04 AM
http://www.aspdotnet-suresh.com/2011/05/how-to-bind-images-from-folder-to.html