Well there are a couple of reasons why this wont work.
I didn't fully test the code because I was just quickly giving you an example and thought that you'd be able to figure it out from there. I work mainly in VB.NET and so I didn't test the loop that you had in your code already...needless to say I did not test the code, it was just an example.
The first problem with the code I posted is that I accidentally left a "<td>" in the src attribute in the ASP code....the ASP code should be:
- <asp:Repeater ID="staticWebPagesRepeater" runat="server">
-
<HeaderTemplate>
-
<table border="1">
-
<tr>
-
<td><b>Web Pages</b></td>
-
</tr>
-
</HeaderTemplate>
-
<ItemTemplate>
-
<tr>
-
<td> <iframe src="<%# Container.DataItem %>"></iframe></td>
-
</tr>
-
</ItemTemplate>
-
<FooterTemplate>
-
</table>
-
</FooterTemplate>
-
</asp:Repeater>
The second thing that is wrong with this code is that when you use the Directory.GetFiles() method it returns you a list of Path And File Names that match the pattern you're searching for.
We stated earlier that you cannot have a local path to a file because the web browser will not be able to download it...web browsers cannot access local files on your computer, it can only access files that exist on the web server and can only do so using a URL. You need to create a URL using the file name.
Because we simply prepended the "/statichtm/" to the file name, and didn't properly extract the name of the file from the Path/FileName your Urls are going to look like:
"/statichtm/D:\PatToVisualStudioProject\1.htm"
Obviously this is not a valid URL....what you really want is just:
"/statichtm/1.htm"
This would have been very obvious if you had used the debugger and stepped through the code.
So what you need to do is fix the ASP code so that the "<td>" is not part of the iframe's src attribute, and modify your loop so that it extracts the file name and then properly create the URLs by prepending "/statichtm/" to the file name extracted.
This is the working VB.NET version of what your code should look like.
- Private _repSource As List(Of String)
-
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
-
_repSource = New List(Of String)
-
Dim fileNames() As String = Directory.GetFiles(Server.MapPath("~/StaticHTM/"), "*.htm")
-
For Each name In fileNames
-
Dim sp() As String = name.Split("\"c)
-
Dim urlToStaticHTML As String = sp(sp.Length - 1)
-
_repSource.Add("/StaticHTM/" + urlToStaticHTML)
-
Next
-
staticWebPagesRepeater.DataSource = _repSource.ToArray
-
staticWebPagesRepeater.DataBind()
-
End Sub
-
C# would look something like (the following is obviously not tested):
- private List<string> _repSource;
-
protected void Page_Load(Object sender, System.EventArgs e)
-
{
-
_repSource = new List<string>();
-
string fileNames[] = Directory.GetFiles(Server.MapPath("~/StaticHTM/"), "*.htm");
-
foreach (string name in fileNames)
-
{
-
string sp[] = name.Split('\');
-
string urlToStaticHTML = sp(sp.Length - 1);
-
_repSource.Add("/StaticHTM/" + urlToStaticHTML );
-
}
-
staticWebPagesRepeater.DataSource = _repSource.ToArray();
-
staticWebPagesRepeater.DataBind();
-
}
In the future, please try to debug the problem before automatically asking for help.