Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# windows server不支持给定路径的格式_C#_Asp.net Mvc_Windows Server 2008 R2 - Fatal编程技术网

C# windows server不支持给定路径的格式

C# windows server不支持给定路径的格式,c#,asp.net-mvc,windows-server-2008-r2,C#,Asp.net Mvc,Windows Server 2008 R2,我有一个web应用程序,我想上传一个excel文件并在应用程序中读取它。当我使用VS或使用windows 7和IIS 7.5在LocalHost中运行应用程序时,一切都很好。但是,当我在使用WindowsServer2008和IIS7.5的服务器上部署应用程序时,我看到两个错误。我使用team viewer连接到服务器,并在服务器上部署了应用程序 当我想从服务器的桌面上传文件时,我看到以下内容,我有管理员权限: Access to the path 'C:\Users\Administrator

我有一个web应用程序,我想上传一个excel文件并在应用程序中读取它。当我使用VS或使用windows 7和IIS 7.5在LocalHost中运行应用程序时,一切都很好。但是,当我在使用WindowsServer2008和IIS7.5的服务器上部署应用程序时,我看到两个错误。我使用team viewer连接到服务器,并在服务器上部署了应用程序

当我想从服务器的桌面上传文件时,我看到以下内容,我有管理员权限:

Access to the path 'C:\Users\Administrator\Desktop\931001.xlsx' is denied.
当我想从另一个pathese上传时,我看到以下错误:

The given path's format is not supported.
以下是我上载文件的尝试:

尝试1:

尝试2:

尝试3:

可能是什么问题?

尝试按如下方式使用:

public ActionResult IndexHTTPostedFileBase文件 { var path=path.CombineServer.MapPath~/Files/,file.FileName; file.SaveAspath; var connectionString=; 如果Path.GetExtensionpath.ToLower=.xslx { connectionString=string.FormatProvider=Microsoft.ACE.OLEDB.12.0;数据源={0};扩展属性=Excel12.0;,路径; } 其他的 { connectionString=string.FormatProvider=Microsoft.Jet.OLEDB.4.0;数据源={0};扩展属性=Excel 8.0;,路径; } var adapter=新的OLEDB数据适配器从[Sheet1$]中选择*,connectionString; var ds=新数据集; 适配器。Fillds,客户; var customer=ds.Tables[customer].AsEnumerable; }
public ActionResult Index(HttpPostedFileBase file)
{
    file.SaveAs(Server.MapPath("~/Files/" + file.FileName));
    var fileName = "/Files/" + file.FileName;
    var connectionString = "";
    if (file.FileName.Split('.').LastOrDefault().ToLower() == "xlsx")
    {
        connectionString = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0}; Extended Properties=Excel 12.0;", Server.MapPath(fileName));
    }
    else
    {
        connectionString = string.Format("Provider=Microsoft.Jet.OLEDB.4.0; data source={0}; Extended Properties=Excel 8.0;", fileName);
    }
    var adapter = new OleDbDataAdapter("SELECT * FROM [Sheet1$]",     connectionString);
    var ds = new DataSet();
    adapter.Fill(ds, "contracts");
    var contracts = ds.Tables["contracts"].AsEnumerable();
}
public ActionResult Index(HttpPostedFileBase file)
{
    var path = Server.MapPath("~/Files/");
    file.SaveAs(Path.Combine(path, file.FileName));
    var fileName = "~/Files/" + file.FileName;
    var connectionString = "";
    if (file.FileName.Split('.').LastOrDefault().ToLower() == "xlsx")
    {
        connectionString = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0}; Extended Properties=Excel 12.0;", Server.MapPath(fileName));
    }
    else
    {
        connectionString = string.Format("Provider=Microsoft.Jet.OLEDB.4.0; data source={0}; Extended Properties=Excel 8.0;", Server.MapPath(fileName));
    }
    var adapter = new OleDbDataAdapter("SELECT * FROM [Sheet1$]", connectionString);
    var ds = new DataSet();
    adapter.Fill(ds, "customer");
    var customer = ds.Tables["customer"].AsEnumerable();
}
public ActionResult Index(HttpPostedFileBase file)
{
    var path = Server.MapPath(@"\Files\");
    file.SaveAs(Path.Combine(path, file.FileName));
    var fileName = @"\Files\" + file.FileName;
    var connectionString = "";
    if (file.FileName.Split('.').LastOrDefault().ToLower() == "xlsx")
    {
        connectionString = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0}; Extended Properties=Excel 12.0;", Server.MapPath(fileName));
    }
    else
    {
        connectionString = string.Format("Provider=Microsoft.Jet.OLEDB.4.0; data source={0}; Extended Properties=Excel 8.0;", Server.MapPath(fileName));
    }
    var adapter = new OleDbDataAdapter("SELECT * FROM [Sheet1$]", connectionString);
    var ds = new DataSet();
    adapter.Fill(ds, "customer");
    var customer = ds.Tables["customer"].AsEnumerable();
}