Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/8.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#应用程序访问数据库的路径_C#_Visual Studio_Ms Access_Publish - Fatal编程技术网

使用已发布的C#应用程序访问数据库的路径

使用已发布的C#应用程序访问数据库的路径,c#,visual-studio,ms-access,publish,C#,Visual Studio,Ms Access,Publish,在access数据库发布/安装到设备后,我需要对其路径进行编码 在任何设备上安装access数据库(用于连接字符串)后,如何获取其路径?有很多方法 Winform Application.StartupPath 返回StartupPath参数(可在运行应用程序时设置) System.IO.Directory.GetCurrentDirectory() 返回当前目录,该目录可能是应用程序所在的文件夹,也可能不是。同样的道理也适用于 Environment.CurrentDirectory。如

在access数据库发布/安装到设备后,我需要对其路径进行编码


在任何设备上安装access数据库(用于连接字符串)后,如何获取其路径?

有很多方法

Winform
Application.StartupPath

  • 返回StartupPath参数(可在运行应用程序时设置)
System.IO.Directory.GetCurrentDirectory()

  • 返回当前目录,该目录可能是应用程序所在的文件夹,也可能不是。同样的道理也适用于
    Environment.CurrentDirectory
    。如果您在DLL中使用此 文件,它将返回进程运行的路径(这是 尤其是在ASP.NET中)
Web

ttpContext.Current.Server.MapPath(); 
  • 获取当前web应用程序根目录的步骤
System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath;