H
hartbypass
Ok, so I thoguht I was close but must be missing something. I am
trying to get a list of files from a directory and display them in a
clickable list using the Repeater control. It seems as if I am getting
the files and adding them to the object, but something is getting lost
or I am not sure how to display on the HTML side. I have something to
the effect of:
HTML side:
<asp:Repeater id="Repeater1" runat="server">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "FileInfoPath") %>
</ItemTemplate>
</asp:Repeater>
Code Side:
private void showFiles(object sender, System.EventArgs e)
{
try
{
appPath = appPath + "/TestApp/";
DirectoryInfo dir = new DirectoryInfo("c:/test");
ArrayList aryFiles = new ArrayList();
FileInfo[] allFiles = dir.GetFiles("*.*");
foreach (FileInfo f in allFiles)
{
FileRelatedInfo objData = new FileRelatedInfo();
objData.FileInfoTitle = f.Name;
objData.FileInfoPath = appPath +
Page.Server.UrlPathEncode(f.Name);
aryFiles.Add(objData.FileInfoPath);
}
Repeater1.DataSource = aryFiles;
Repeater1.DataBind();
}
catch(Exception ex)
{
Response.Write(ex.ToString());
}
}
public class FileRelatedInfo
{
public string FileInfoTitle;
public string FileInfoPath;
}
Error from try/catch block:
System.Web.HttpException: DataBinder.Eval: 'System.String' does not
contain a property with the name FileInfoPath. at
System.Web.UI.DataBinder.GetPropertyValue(Object container, String
propName) at System.Web.UI.DataBinder.Eval(Object container, String[]
expressionParts) at System.Web.UI.DataBinder.Eval(Object container,
String expression) at ASP.usrFileList_ascx.__DataBind__control3(Object
sender, EventArgs e)
trying to get a list of files from a directory and display them in a
clickable list using the Repeater control. It seems as if I am getting
the files and adding them to the object, but something is getting lost
or I am not sure how to display on the HTML side. I have something to
the effect of:
HTML side:
<asp:Repeater id="Repeater1" runat="server">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "FileInfoPath") %>
</ItemTemplate>
</asp:Repeater>
Code Side:
private void showFiles(object sender, System.EventArgs e)
{
try
{
appPath = appPath + "/TestApp/";
DirectoryInfo dir = new DirectoryInfo("c:/test");
ArrayList aryFiles = new ArrayList();
FileInfo[] allFiles = dir.GetFiles("*.*");
foreach (FileInfo f in allFiles)
{
FileRelatedInfo objData = new FileRelatedInfo();
objData.FileInfoTitle = f.Name;
objData.FileInfoPath = appPath +
Page.Server.UrlPathEncode(f.Name);
aryFiles.Add(objData.FileInfoPath);
}
Repeater1.DataSource = aryFiles;
Repeater1.DataBind();
}
catch(Exception ex)
{
Response.Write(ex.ToString());
}
}
public class FileRelatedInfo
{
public string FileInfoTitle;
public string FileInfoPath;
}
Error from try/catch block:
System.Web.HttpException: DataBinder.Eval: 'System.String' does not
contain a property with the name FileInfoPath. at
System.Web.UI.DataBinder.GetPropertyValue(Object container, String
propName) at System.Web.UI.DataBinder.Eval(Object container, String[]
expressionParts) at System.Web.UI.DataBinder.Eval(Object container,
String expression) at ASP.usrFileList_ascx.__DataBind__control3(Object
sender, EventArgs e)