Downloading a file.............

Last post 08-17-2009 2:13 AM by pradeephv4u. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 01-27-2009 6:44 AM

    Downloading a file.............

     Can any one help me in downloading a file from a grid...... i mean first i ve listed the files on datagrid, and then i want to provide the link in last so that i can download the file on clicking the link....

    I am using MS-SQL-2000 in backend

    Thank u in advance

    Pradeep

    pradeephv4u@gmail.com

  •  Advertisement

    Featured Advertisement

     
  • 01-27-2009 8:46 AM In reply to

    • xxxd
    • Top 10 Contributor
    • Joined on 12-18-2006
    • Slacker
    • Points 19,057

    Re: Downloading a file.............

     DataGrid is really an old timer, in asp .net 2.0, Gridview is default data control. In the gridview you can always use hyperlink column as such

    <asp:HyperLinkField DataNavigateUrlFields="LunWBT" DataNavigateUrlFormatString="files/{0}.doc" HeaderText="Download"  Text="This file" />

  • 01-27-2009 9:11 AM In reply to

    Re: Downloading a file.............

    Parser Error

    Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.

    Parser Error Message: System.Web.UI.WebControls.DataGridColumnCollection must have items of type 'System.Web.UI.WebControls.DataGridColumn'. 'asp:HyperLinkField' is of type 'System.Web.UI.WebControls.HyperLinkField'.

    I am getting this kind of error......... wat should i do now...??

  • 01-27-2009 10:18 AM In reply to

    • xxxd
    • Top 10 Contributor
    • Joined on 12-18-2006
    • Slacker
    • Points 19,057

    Re: Downloading a file.............

    Do you use gridview? If not, then you should.  

    <asp:GridView ID="GridView1" runat="server" BackColor="White" BorderColor="White"
                BorderStyle="Ridge" BorderWidth="2px" CellPadding="3" CellSpacing="1" 

    GridLines="None" AutoGenerateColumns="False">
                <FooterStyle BackColor="#C6C3C6" ForeColor="Black" />
                <RowStyle BackColor="#DEDFDE" ForeColor="Black" />
                <PagerStyle BackColor="#C6C3C6" ForeColor="Black" HorizontalAlign="Right" />
                <SelectedRowStyle BackColor="#9471DE" Font-Bold="True" ForeColor="White" />
                <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#E7E7FF" />
                <Columns>
                    <asp:BoundField DataField="CategoryID" />
                    <asp:HyperLinkField DataNavigateUrlFields="CategoryID"

     DataNavigateUrlFormatString="SmallWindow.aspx?id={0}"
                        DataTextField="CategoryName" NavigateUrl="SmallWindow.aspx" />
                    <asp:BoundField DataField="Description" />
                </Columns>
            </asp:GridView>

  • 08-17-2009 2:13 AM In reply to

    Re: Downloading a file.............

    Hi,

    check this code

     

    string strFilePath = folderPath + "\\" + GridView1.SelectedRow.Cells[0].Text;

    FileStream sourceFile = new FileStream(@strFilePath, FileMode.OpenOrCreate);

    long FileSize;

    FileSize = sourceFile.Length;

    byte[ getContent = new byte[(int)FileSize];

    sourceFile.Read(getContent, 0, (int)sourceFile.Length);

    sourceFile.Close();

    Response.ContentType = sourceFile.ToString();

    Response.AddHeader("content-disposition", "attachment;filename=" + GridView1.SelectedRow.Cells[0].Text + "");

    Response.BinaryWrite(getContent);

     

     

    Hope this will help you

    Regards

    Pradeep

Page 1 of 1 (5 items)