1

Hello to all,

I've designed a website to provide Software and all the data is coming into the gridview.The entries in database are......

SoftName : Name of the software

SoftType : Type of the software (like windows,mac etc.)

SoftUrl : Path of the software file in the website
(It is a folder "Soft")

Now I want to add a download link into the gridview that'll make the user to download directly my software from the Gridview.

Thanks in advance.......

Edited by KM499: n/a

4
Contributors
11
Replies
19
Views
7 Years
Discussion Span
Last Post by KM499
Featured Replies
  • 1

    Error coming as.......... [CODE] 'System.Web.HttpResponse' does not contain a definition for 'ClearHeader' and no extension method 'ClearHeader' accepting a first argument of type 'System.Web.HttpResponse' could be found (are you missing a using directive or an assembly reference?) [/CODE] Read More

  • 1

    Its for a single file i.e., test.zip.......But I'm getting a list of software stuff from the database into the gridview........How can I code for every file???? Read More

  • 1
    __avd 1,826   7 Years Ago

    You must have to read those links which I have posted in your previous thread. You need to handle the event of GridView control. Markup [code] <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" onrowcommand="GridView1_RowCommand"> <Columns> <asp:TemplateField> <ItemTemplate> <asp:LinkButton ID="LinkButton1" runat="server" CommandArgument='<%# Eval("url") %>' CommandName="cmd">Download</asp:LinkButton> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> [/code] Code-behind [code] protected void … Read More

  • 1

    I must say that you're a total genius for me bro...This was the only problem that I was facing for many days and because of you I've found my solution and the end of my project too....May u get whatever you need........Thanks a lot man........ Read More

  • 1
    __avd 1,826   7 Years Ago

    You're welcome. I'm glad you got it working. Read More

0

See,

string filename="test.zip";
string path=MapPath("~/soft/" + filename);

byte []bts=System.IO.File.ReadAllBytes(path);

Response.Clear();
Response.ClearHeader();

Response.AddHeader("Content-Type","Application/octet-stream")
Response.AddHeader("Content-Length",bts.Length.ToString());
Response.AddHeader("Content-Disposition","attachment; filename=" + filename);
Response.BinaryWrite(bts);
Response.Flush();
Response.End();

Edited by __avd: n/a

1

Error coming as..........

'System.Web.HttpResponse' does not contain a definition for 'ClearHeader' and no extension method 'ClearHeader' accepting a first argument of type 'System.Web.HttpResponse' could be found (are you missing a using directive or an assembly reference?)

Edited by KM499: n/a

1

Its for a single file i.e., test.zip.......But I'm getting a list of software stuff from the database into the gridview........How can I code for every file????

0

You must have to read those links which I have posted in your previous thread. You need to handle the event of GridView control.

Markup

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
            onrowcommand="GridView1_RowCommand">
            <Columns>
                <asp:TemplateField>
                    <ItemTemplate>
                        <asp:LinkButton ID="LinkButton1" runat="server" 
                            CommandArgument='<%# Eval("url") %>' CommandName="cmd">Download</asp:LinkButton>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>

Code-behind

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "cmd")
        {
            string filename=e.CommandArgument.ToString();
            string path=MapPath("~/soft/" + filename);
            byte []bts=System.IO.File.ReadAllBytes(path);

            Response.Clear();
            Response.ClearHeaders();

            Response.AddHeader("Content-Type", "Application/octet-stream");
            Response.AddHeader("Content-Length",bts.Length.ToString());
            Response.AddHeader("Content-Disposition","attachment; filename=" + filename);
            Response.BinaryWrite(bts);
            Response.Flush();
            Response.End();
        }
    }

PS: Try to mark thread as solved if you have found an answer to your question.

1

You must have to read those links which I have posted in your previous thread. You need to handle the event of GridView control.

Markup

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
            onrowcommand="GridView1_RowCommand">
            <Columns>
                <asp:TemplateField>
                    <ItemTemplate>
                        <asp:LinkButton ID="LinkButton1" runat="server" 
                            CommandArgument='<%# Eval("url") %>' CommandName="cmd">Download</asp:LinkButton>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>

Code-behind

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "cmd")
        {
            string filename=e.CommandArgument.ToString();
            string path=MapPath("~/soft/" + filename);
            byte []bts=System.IO.File.ReadAllBytes(path);

            Response.Clear();
            Response.ClearHeaders();

            Response.AddHeader("Content-Type", "Application/octet-stream");
            Response.AddHeader("Content-Length",bts.Length.ToString());
            Response.AddHeader("Content-Disposition","attachment; filename=" + filename);
            Response.BinaryWrite(bts);
            Response.Flush();
            Response.End();
        }
    }

PS: Try to mark thread as solved if you have found an answer to your question.

1

I must say that you're a total genius for me bro...This was the only problem that I was facing for many days and because of you I've found my solution and the end of my project too....May u get whatever you need........Thanks a lot man........

0

hi,

i'm trying to use your code,
but i don't know what should i write instead of the: <%# Eval("url") %>

can you pls help?

thanks.

0

adatapost. you're a super hero. U solved my problem. this is what exactly i wanted. May you long live with whatever u wanted in your life

1

Hello,

This "url" refers to the path of the folder contained in the project like in my case it was a folder named "Soft" and hence I wrote <%# Eval("~/Soft/") %>
Hope that helps.

Thanks in advance.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.