无法将我的excel文件保存在我在项目中创建的文件夹中...我想我在进行路径规范化时忘记了一些内容...也许我之后需要做些什么? 我已经向用户授予权限之类的东西,我认为该文件未打开,我只有1个用户,并且没有打开。 这是代码专家:
protected void Upload_Click(object sender, EventArgs e)
{
string excelPath = Server.MapPath("~/Files/") + Path.GetFileName(FileUpload1.PostedFile.FileName);
FileUpload1.SaveAs(excelPath);
string filepath = Server.MapPath("~/Files/");
string filename = Path.GetFileName(filepath);
string ext = Path.GetExtension(filename);
String strConnection = @"Data Source=PEDRO-PC\SQLEXPRESS;Initial Catalog=costumizado;Persist Security Info=True;User ID=sa;Password=1234";
string excelConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + filepath + ";Extended Properties=\"Excel 12.0 Xml;HRD=YES;IMEX=1;\"";
OleDbConnection excelConnection = new OleDbConnection(excelConnectionString);
OleDbCommand cmd = new OleDbCommand("Select [Name],[city],[age] from [Sheet1$]", excelConnection);
excelConnection.Open();
cmd.ExecuteNonQuery();
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter("Select [Name],[city],[age] from [Sheet1$]", strConnection);
OleDbDataReader dReader;
dReader = cmd.ExecuteReader();
SqlBulkCopy sqlBulk = new SqlBulkCopy(strConnection);
sqlBulk.DestinationTableName = "Test";
sqlBulk.WriteToServer(dReader);
excelConnection.Close();
}