Click here to Skip to main content
15,879,613 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Access to the path -Url here- is denied.
my Code id
UploadData is a folder in Server
String filepath = Server.MapPath("UploadData");
        FileUpload1.SaveAs(filepath + "\\" + FileUpload1.FileName.Split('\\')[FileUpload1.FileName.Split('\\').Length - 1]);
        string excelPath = (filepath + "\\" + FileUpload1.FileName.Split('\\')[FileUpload1.FileName.Split('\\').Length - 1]);
        string OledbConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + excelPath + ";Extended Properties=Excel 8.0;";
        OleDbConnection cn = new OleDbConnection(OledbConnectionString);
            string query = string.Format(" select * from [{0}]", "Sheet1$");
            OleDbDataAdapter ad = new OleDbDataAdapter(query, cn);
            DataSet ds = new DataSet();
            ad.Fill(ds, "Attendance");
            DataTable dt = ds.Tables[0];
            foreach (DataRow dr in dt.Rows)
                string FName = dr[0].ToString();
                string Lname = dr[1].ToString();
                string Att = dr[2].ToString();
                string QU = "insert into ABC values('" + FName + "','" + Lname + "','" + Att + "')";
                SqlConnection cnp = new SqlConnection(bl.Cn);
                SqlCommand cmd = new SqlCommand(QU,cnp);
            Label1.Text = "ok";
        catch (Exception e)
            Label1.Text = e.Message;

1 solution

You are trying to save to a network location, which is not allowed by default.

Try to impersonate a user account which has access to that location.[^]

To learn more about impersonation[^]
Share this answer
E.msk 6-Jun-11 7:09am    
Thanks Prerak Patel
Prerak Patel 6-Jun-11 7:30am    
You are welcome.
Prerak Patel 6-Jun-11 7:34am    
You should vote the answer 5 while accepting the answer, that is normal practice here. Someone has voted it 1.

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