Click here to Skip to main content
16,004,833 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Friends

I want to show text files content on repeater so I am trying to write the files content on Literal control and bind this Literal with repeater.
But It is showing only recent text files name but not the content of file.So Please help me.

What I have done is written below:

This is on Blog.ascx.cs page-
C#
protected void btnRead_Click1(object sender, EventArgs e)
{
    da = new SqlDataAdapter("select Top(1)blogpath from images order by id desc", con);
    //da = new SqlDataAdapter("select Id, blogpath from images where Id=(select Max(Id) from images)", con);
    ds = new DataSet();
    da.Fill(ds);
    Lit.Text = ds.Tables[0].Rows[0]["BlogPath"].ToString();
    Lit.DataBind();

    string name = ds.Tables[0].Rows[0]["BlogPath"].ToString();
    string filePath = blgFile.PostedFile.FileName;
    if (System.IO.File.Exists(Server.MapPath("~/TextFiles/Blogs/") + name))
    {
        string fileName = Server.MapPath("~/TextFiles/Blogs/") + name;
        String contents = File.ReadAllText(fileName);

ds = new DataSet();
                da.Fill(ds);
                rptrBlg.DataSource = ds;
                rptrBlg.DataBind();
                Lit1.Text = contents.ToString();
            }
        }
    }

This is on Blog.ascx page-

<div>
<asp:Repeater ID="rptrBlg" runat="server">
<HeaderTemplate>
<table border="0" width="600px" cellpadding="2" cellspacing="1" style="border: 1px solid maroon;">
        <tr bgcolor="pink">
        <th>Blog</th>
        </tr>
</HeaderTemplate>
<itemtemplate>
<table><tbody><tr><td>
<%# DataBinder.Eval(Container.DataItem,"BlogPath") %>
<asp:Literal ID="Lit1" runat="server">
</td></tr></tbody></table>
</itemtemplate>

</table></div>

Thanks in Advance
Akhilesh Pathak
Posted
Updated 13-Mar-13 20:50pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900