从gridview asp.net c#下载文件时出现错误信息 [英] Error message when download file from gridview asp.net c#

查看:65
本文介绍了从gridview asp.net c#下载文件时出现错误信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨^ _ ^



i从gridview下载文件时出错



i保存的路径数据库和项目文件夹中的文件,



这是错误信息:



< a href => http://www.4shared.com/photo/1qvk0uBC/one。 html [ ^ ]



这是使用gridview的下载代码文件:



  protected   void  Button3_Click( object  sender,EventArgs e)
{

按钮bn =发件人 as 按钮;
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)); // 错误在这里
Response.End();



}





这是上传代码:



 受保护 无效 Button1_Click( object  sender,EventArgs e)
{

string filename2 = Path.GetFileName(FileUpload1.PostedFile.FileName);
FileUpload1.SaveAs(Server.MapPath( Files / + filename2));
SqlCommand com = new SqlCommand( insert进入歌曲(sname,path)值(@ 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();


}





任何帮助?

解决方案

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





请在关闭web.config中system.web的标签之前复制第一行文件。


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:

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 :

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 ?

解决方案

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



Please copy first line before closing tag of system.web in your web.config file.


这篇关于从gridview asp.net c#下载文件时出现错误信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆