Click here to Skip to main content
16,018,534 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
My Grid view code for download link buttion:
XML
<asp:TemplateField HeaderText="Download">
               <ItemTemplate>
                   <asp:LinkButton ID="LinkButton1" runat="server"
                       Text='<%# Eval("Files") %>' CommandArgument='<%# Eval("Files") %>'
                       onclick="LinkButton1_Click" ></asp:LinkButton>
               </ItemTemplate>



I am using folder to store the file........

C#
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
      {
          Response.Clear();
          Response.ContentType = "application/octet-stream";
          Response.AppendHeader("Content-Disposition", "filename=" + e.CommandArgument);
          <big></big><big>Response.TransmitFile(Server.MapPath("~/Files/") + e.CommandArgument);</big>
          Response.End();
      }




When using a grid view paging cannot find the path in the folder.....
please help me i am doing project.....
Could not find file 'C:\Users\THAMILARASAN\Desktop\Back up2\Virtual Classroom\Virtual Classroom\Files\2'.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.IO.FileNotFoundException: Could not find file 'C:\Users\THAMILARASAN\Desktop\Back up2\Virtual Classroom\Virtual Classroom\Files\2'.

Source Error:


Line 27: Response.ContentType = "application/octet-stream";
Line 28: Response.AppendHeader("Content-Disposition", "filename=" + e.CommandArgument);
Line 29: Response.TransmitFile(Server.MapPath("~/Files/") + e.CommandArgument);
Line 30: Response.End();
Line 31: }
Posted

Your CommandArgument isn't a filename that exists in that path. It looks like you might be missing an extension or something. We can't see your data or your file system so it's hard to advise much further than that.
 
Share this answer
 
The RowCommand event fires for every command event, which includes clicking on the links to the different pages.

You need to specify a CommandName on your LinkButton, and verify that the event is firing for your command:
ASP.NET
<asp:TemplateField HeaderText="Download">
<ItemTemplate>
    <asp:LinkButton ID="LinkButton1" runat="server"
	    Text='<%# Eval("Files") %>' 
	    CommandArgument='<%# Eval("Files") %>'
	    CommandName="DownloadFiles"
        onclick="LinkButton1_Click"
    />
</ItemTemplate>
</asp:TemplateField>

C#
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
    if (e.CommandName == "DownloadFiles")
    {
        Response.Clear();
        Response.ContentType = "application/octet-stream";
        Response.AppendHeader("Content-Disposition", "filename=" + e.CommandArgument);
        Response.TransmitFile(Server.MapPath("~/Files/") + e.CommandArgument);
        Response.End();
    }
}
 
Share this answer
 
Comments
thamil arasan 24-Mar-15 11:29am    
thank you so much friend it's really helpfull........thank you man..........∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞

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