部署时,文件上载在ASP.NET中不起作用

时间:2015-03-24 14:28:22

标签: c# asp.net

这段代码在localhost上运行正常,但是当我尝试在服务器中运行此代码时,它无法运行..有人能告诉我什么是错的吗?

private void SaveFileToDatabase(string filePath)
    {
        String strConnection = "Data Source=.;Initial Catalog=EkkiDB;Integrated Security=TRUE";

        String excelConnString = String.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=\"Excel 12.0\"", filePath);
        //Create Connection to Excel work book 
        using (OleDbConnection excelConnection = new OleDbConnection(excelConnString))
        {
            //Create OleDbCommand to fetch data from Excel 
            using (OleDbCommand cmd = new OleDbCommand("Select [SurveyDate],[DealerName],[Model],[HP],[Quantity],[ID] from [Sheet1$]", excelConnection))
            {
                excelConnection.Open();
                using (OleDbDataReader dReader = cmd.ExecuteReader())
                {
                    using (SqlBulkCopy sqlBulk = new SqlBulkCopy(strConnection))
                    {
                        //Give your Destination table name 
                        sqlBulk.DestinationTableName = "Import_Survey";
                        sqlBulk.WriteToServer(dReader);
                    }
                }
            }
        }
    }


    private string GetLocalFilePath( FileUpload fileUploadControl)
    {

        //string filePath = Server.MapPath(fileUploadControl.FileName);
       // string filePath = Path.Combine(saveDirectory);
        string filePath = Server.MapPath("~/xl/") + Path.GetFileName(fileUploadControl.PostedFile.FileName);
        fileUploadControl.SaveAs(filePath);

        return filePath;

    }

1 个答案:

答案 0 :(得分:0)

目的地目录在哪里?如果它不在IIS控制之下,请检查您的匿名用户帐户是否具有写入权限。