Repeater and File List Help

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)
 
G

Guest

You are adding a string into the aryFiles ArrayList which you are then
setting as the DataSource and in the Eval statement you are trying to get a
property named "FileInfoPath" from the string that you entered. System.String
(the same as "string") does not have a property called "FileInfoPath".

Changing the line "aryFiles.Add(objData.FileInfoPath);" to
"aryFiles.Add(objData);" will sort your problem.

Hope this helps.
 
H

hartbypass

Sorry about that, I did not realize I left that line in there. I was
just adding the objData and was getting this:

System.Web.HttpException: DataBinder.Eval:
'SMIntranet.UserControls.usrFileList+FileRelatedInfo' 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)

I added the objData.FileInfo­Path just shooting in the dark.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top