Click here to Skip to main content
15,892,809 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi ^_^

i have an error when download files from gridview

i saved path in data base and files in a folder in project files ,

and this is error message:

http://www.4shared.com/photo/1qvk0uBC/one.html[^]

this is download code file using gridview:

C#
protected void Button3_Click(object sender, EventArgs e)
    {
        
        Button bn = sender as Button;
        GridViewRow gr = bn.NamingContainer as GridViewRow;
        string path = GridView1.DataKeys[gr.RowIndex].Value.ToString();
        Response.ContentType = "image/jpg";
        Response.AddHeader("Content-Disposition", "attachment;filename=\"" + path + "\"");
        Response.TransmitFile(Server.MapPath(path)); // The error is here
        Response.End();
        

        
    }


and this is upload code :

C#
protected void Button1_Click(object sender, EventArgs e)
   {

           string filename2 = Path.GetFileName(FileUpload1.PostedFile.FileName);
           FileUpload1.SaveAs(Server.MapPath("Files/" + filename2));
           SqlCommand com = new SqlCommand("insert into song (sname,path) values (@s,@p)", c1.cn);
           com.Parameters.AddWithValue("@s", SqlDbType.NVarChar).Value = TextBox1.Text;
           com.Parameters.AddWithValue("@p", SqlDbType.NVarChar).Value = "Files/" + filename2;
           c1.cn.Open();
           com.ExecuteNonQuery();
           c1.cn.Close();


   }


any help ?
Posted
Comments
Richard C Bishop 15-Jan-13 15:12pm    
What is the error message? Have you set a breakpoint at the declaration of the "path" variable to see what value it is being assigned?
leana88 15-Jan-13 15:46pm    
The value path is nvarchar(MAX)
This is table :

id int
sname nvarchar(MAX)
path nvarchar(MAX)
Member 9581488 15-Jan-13 15:36pm    
What is the value of path? Also, You have to define path when downloading file. Where you upload your file?
leana88 15-Jan-13 15:43pm    
The value path is nvarchar(MAX)
This is table :

id int
sname nvarchar(MAX)
path nvarchar(MAX)
Member 9581488 15-Jan-13 15:48pm    
Details provided by you is datatype of path. I asked the value of path on this line
string path = GridView1.DataKeys[gr.RowIndex].Value.ToString();

put breakpoint and see the value.

1 solution

<httpRuntime maxRequestLength="2097151" executionTimeout="9999"/>
	</system.web>


Please copy first line before closing tag of system.web in your web.config file.
 
Share this answer
 
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