简体   繁体   English

c#winforms GetCurrentDirectory返回C:\\ WINDOWS \\ System32 \\设计错误

[英]c# winforms GetCurrentDirectory returns C:\WINDOWS\System32\ design error

I'm making like a cashier app with a winforms project and i need to use an access database and i used System.IO.GetCurrentDirectory() . 我正在制作一个带有winforms项目的收银应用程序,我需要使用访问数据库,并且使用了System.IO.GetCurrentDirectory() But it returns C:\\WINDOWS\\System32 on design time so it keeps popping up message boxes when i'm using the designer. 但是它在设计时返回C:\\WINDOWS\\System32 ,所以当我使用设计器时它会不断弹出消息框。

It also returns the correct directory when i run it. 当我运行它时,它还会返回正确的目录。

Here's an example of my connection string: 这是我的连接字符串的示例:

OleDbConnection conn = new OleDbConnection();
string dataPath = System.IO.Directory.GetCurrentDirectory();
conn.ConnectionString = @"
Provider=Microsoft.ACE.OLEDB.12.0;
Data Source=" + dataPath + "/Data/Databases/database.accdb;Persist Security Info=False";

Any help will be appriciated. 任何帮助将被申请。

Edit: 编辑:

What happens when i try to open the designer: https://i.stack.imgur.com/HQjHa.png 当我尝试打开设计器时会发生什么: https : //i.stack.imgur.com/HQjHa.png

Not sure why this is happening but u can try : 不知道为什么会这样,但是您可以尝试:

System.Environment.CurrentDirectory

//or

Application.StartupPath

//or

System.IO.Path.GetDirectoryName(Application.ExecutablePath);

//or

System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);

//or

System.AppDomain.CurrentDomain.BaseDirectory

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C#Directory.GetCurrentDirectory()返回带有NUnit的system32 - C# Directory.GetCurrentDirectory() returning system32 with NUnit C#错误Windows启动时,对路径'C:\\ Windows \\ system32 \\ Com \\ dmp'的访问被拒绝 - C# Error Access to the path 'C:\Windows\system32\Com\dmp' is denied When Windows Startup 我希望我的C#winforms程序将其自身复制到system32 - I want my C# winforms program to copy it self to system32 通过total-commander在C:\\ Windows \\ system32中打开c#文件夹 - c# open folder in C:\Windows\system32 via total-commander 使用C#从c:\\ windows \\ system32删除文件时遇到问题 - Trouble deleting a file from c:\windows\system32 using C# 在C#中访问System32 \\ config \\ SYSTEM配置单元 - Access System32\config\SYSTEM hive in C# 为什么我收到这个错误: System.UnauthorizedAccessException: 'C:\\Windows\\system32\\CSV_file' - why to I get this error: System.UnauthorizedAccessException: 'C:\Windows\system32\CSV_file' 如何通过C#语言删除Windows 7 dll文件(在System32文件夹中) - How Delete A Windows 7 dll File (In System32 Folder) By C# Language 如何在 C# 中获取 Windows\system32\config\systemprofile\AppData\Local\ 文件夹路径? - How to get Windows\system32\config\systemprofile\AppData\Local\ folder path in C#? 拒绝访问路径“ C:\\ Windows \\ System32 \\” - Access to the path 'C:\Windows\System32\ is denied
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM