Click here to Skip to main content
15,891,372 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to Edit Grid View Rows along with file download option. I can execute Edit and File download separately. But when I execute both, and press Edit button, it gives me error:Could not find a part of the path 'c:\upload\'. This path is right and file download can be executed from this path.

C#
namespace gerp_support
{
    public partial class Admin : System.Web.UI.Page
    {
        string cs = ConfigurationManager.ConnectionStrings["GerpConnStr"].ConnectionString;
        SqlConnection con;
        SqlDataAdapter adapt;
        DataTable dt;  


        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                this.ShowData();
            }
        }

        private void ShowData()
        {
            dt = new DataTable();
            con = new SqlConnection(cs);
            con.Open();
            adapt = new SqlDataAdapter("SELECT ID,request_no,requestor,request_type, request_area, subject,description,attachment,req_status,admin_comment FROM request where req_status='Open' order by ID", con);



            adapt.Fill(dt);
            if (dt.Rows.Count > 0)
            {
                GridView1.DataSource = dt;
                GridView1.DataBind();
            }
            con.Close();

        }




        protected void GridView1_RowEditing(object sender, System.Web.UI.WebControls.GridViewEditEventArgs e)
        {
            //NewEditIndex property used to determine the index of the row being edited.  
            GridView1.EditIndex = e.NewEditIndex;
            ShowData();
        }



        protected void gvFiles_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            Response.Clear();
            Response.ContentType = "application/octet-stream";

           // Response.AppendHeader("Content-Disposition", "filename=" + e.CommandArgument);

            Response.AppendHeader("Content-Disposition", "attachment; filename=" + e.CommandArgument);

            string p = @"c:\upload\";

             Response.TransmitFile(p + e.CommandArgument);

          //  Response.TransmitFile(@"~\upload\" + e.CommandArgument);

            Response.End();
        }  

        protected void GridView1_RowUpdating(object sender, System.Web.UI.WebControls.GridViewUpdateEventArgs e)
        {
            //Finding the controls from Gridview for the row which is going to update  

            Label id = GridView1.Rows[e.RowIndex].FindControl("lbl_id") as Label;
            Label request_no = GridView1.Rows[e.RowIndex].FindControl("lbl_request_no") as Label;
            Label requestor = GridView1.Rows[e.RowIndex].FindControl("lbl_requestor") as Label;
            Label request_type = GridView1.Rows[e.RowIndex].FindControl("lbl_request_type") as Label;
            Label request_area = GridView1.Rows[e.RowIndex].FindControl("lbl_request_area") as Label;
            Label subject = GridView1.Rows[e.RowIndex].FindControl("lbl_subject") as Label;
            Label description = GridView1.Rows[e.RowIndex].FindControl("lbl_description") as Label;




            TextBox req_status = GridView1.Rows[e.RowIndex].FindControl("txt_req_status") as TextBox;
            TextBox admin_comment = GridView1.Rows[e.RowIndex].FindControl("txt_admin_comment") as TextBox;

            con = new SqlConnection(cs);
            con.Open();

            SqlCommand cmd = new SqlCommand("Update request set req_status='" +req_status.Text+ "',admin_comment='" +admin_comment.Text+ "' where ID=" + Convert.ToInt32(id.Text), con);
            cmd.ExecuteNonQuery();
 con.Close();

           GridView1.EditIndex = -1;

            ShowData();
}


What I have tried:

I have tried Edit Grid View Row and File Download separately and it worked. But when I execute both and press Edit button, it gives error:Could not find a part of the path 'c:\upload\'
Posted
Updated 11-Jul-16 23:35pm
v2
Comments
rajib saiful 12-Jul-16 5:58am    
Hi
Please get screenshot of Error message at below link. When Edit button is pressed, this error message comes. Not getting attachment upload option here.

http://stackoverflow.com/questions/38319744/transmitfile-gives-error-could-not-find-a-part-of-the-path-c-upload

BR
Rajib
Richard Deeming 12-Jul-16 9:01am    
When you debug your code, what is the value of e.CommandArgument?
ZurdoDev 12-Jul-16 13:28pm    
If the path is correct, meaning that path exists wherever the code is running from, then it is likely a permissions issue.
rajib saiful 13-Jul-16 0:53am    
Thank you RyanDev for the reply. From this path, file is downloaded, but Edit button pressing giving this error. Which indicating there is no permission issue. Please comment if I am missing someting.

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