Hello all..
thanks for my last forum..for better solution with fast reply..

I have getting problem with display link button on page aspx.cs ..
I have requirement as below.....

i am trying to display file name with remove link after attached
file.I have done code on aspx.cs as below and get success to display
file name after attaching it...
Below is my code for aspx.cs file:

if (FileUpload1.HasFile)
        {
            this.FileUpload1.SaveAs(Server.MapPath("upload\\" + FileUpload1.FileName));
            this.Label1.Text = "File Uploaded Sucessfull!!!!";
            DirectoryInfo dInfo = new DirectoryInfo(Server.MapPath("upload"));
            FileInfo[] FilesList = dInfo.GetFiles();
            int i = 1;
            foreach (FileInfo fi in FilesList)
            {
               
                Label li = new Label();
                Response.Write("<h2>"+i+"."+fi.Name+"</h2>");
                Response.Write("</br>");
                i++;
            }

output is :
1.file1.txt
2.file2.txt
3.file3.txt

I want beside this file name Remove link..as user attached files.(it means dynamically)
I have tried below on aspx.cs file.

Response.Write("<asp:LinkButton  ID=LinkButton1 runat=server> Remove </asp:LinkButton> ");

I hope U can able to understand situation and help me....
reply sir...

Recommended Answers

All 3 Replies

You can not add server control using Response.Write method. Use hyperlink,

protected void Page_Load(object sender, EventArgs e)
    {
        if(Request["file"]!=null){
            string path = MapPath("~/upload/" + Request["file"]);
            File.Delete(path);
        }
        
        DirectoryInfo dInfo = new DirectoryInfo(Server.MapPath("~/upload"));
        FileInfo[] FilesList= dInfo.GetFiles();
        int i = 1;
        foreach (FileInfo fi in FilesList)
        {
            Response.Write("<h2>" + i + "." + fi.Name + "</h2>");
            Response.Write("<a href='" + Request.CurrentExecutionFilePath   + "?file=" + fi.Name + "'>Remove</a>");
            Response.Write("</br>");
            i++;
        }
    }

Thanks once again.....
it work properly....
thank u so much...
Can I know your name sir...?

You can not add server control using Response.Write method. Use hyperlink,

protected void Page_Load(object sender, EventArgs e)
    {
        if(Request["file"]!=null){
            string path = MapPath("~/upload/" + Request["file"]);
            File.Delete(path);
        }
        
        DirectoryInfo dInfo = new DirectoryInfo(Server.MapPath("~/upload"));
        FileInfo[] FilesList= dInfo.GetFiles();
        int i = 1;
        foreach (FileInfo fi in FilesList)
        {
            Response.Write("<h2>" + i + "." + fi.Name + "</h2>");
            Response.Write("<a href='" + Request.CurrentExecutionFilePath   + "?file=" + fi.Name + "'>Remove</a>");
            Response.Write("</br>");
            i++;
        }
    }

>Can I know your name sir...?

adatapost

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.