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

时间:2016-02-25 13:23:20

标签: c# visual-studio ms-access publish

我需要在将访问数据库发布/安装到设备后对其进行编码。

在任何设备上安装后,如何获取访问数据库(连接字符串)的路径?

1 个答案:

答案 0 :(得分:0)

有很多方法

<强> Winform的 Application.StartupPath

  
      
  • 返回StartupPath参数(可在运行应用程序时设置)
  •   

System.IO.Directory.GetCurrentDirectory()

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

网络

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