Excel文件上传错误-拒绝访问此处的路径..url. [英] Excel File Upload Error - Access to the path ..url Here..is denied.
本文介绍了Excel文件上传错误-拒绝访问此处的路径..url.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
拒绝访问-Url here-路径.
我的代码ID
UploadData是服务器中的文件夹
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);
cn.Open();
try
{
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);
cnp.Open();
SqlCommand cmd = new SqlCommand(QU,cnp);
cmd.ExecuteNonQuery();
cn.Close();
cnp.Close();
}
Label1.Text = "ok";
}
catch (Exception e)
{
cn.Close();
Label1.Text = e.Message;
}
}
推荐答案
); OleDbDataAdapter ad =新的OleDbDataAdapter(query,cn); DataSet ds = new DataSet(); ad.Fill(ds,"Attendance"); DataTable dt = ds.Tables [0]; foreach(dt.rows中的DataRow dr) { 字符串FName = dr [0] .ToString(); 字符串Lname = dr [1] .ToString(); 字符串Att = dr [2] .ToString(); 字符串QU =插入ABC值(""+ FName +"''," + Lname +'',""+ Att +"''); SqlConnection cnp =新的SqlConnection(bl.Cn); cnp.Open(); SqlCommand cmd =新的SqlCommand(QU,cnp); cmd.ExecuteNonQuery(); cn.Close(); cnp.Close(); } Label1.Text =确定"; } 捕获(异常e) { cn.Close(); Label1.Text = e.Message; } }
"); 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); cnp.Open(); SqlCommand cmd = new SqlCommand(QU,cnp); cmd.ExecuteNonQuery(); cn.Close(); cnp.Close(); } Label1.Text = "ok"; } catch (Exception e) { cn.Close(); Label1.Text = e.Message; } }
您正尝试保存到默认情况下不允许的网络位置.
尝试模拟可以访问该位置的用户帐户.
http://msdn.microsoft.com/en-us/library/aa292118 (v = vs.71).aspx [ http://www.google.com/search?q=impersonate+%2Basp.net [ ^ ]
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.
http://msdn.microsoft.com/en-us/library/aa292118(v=vs.71).aspx[^]
To learn more about impersonation
http://www.google.com/search?q=impersonate+%2Basp.net[^]
这篇关于Excel文件上传错误-拒绝访问此处的路径..url.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文