简体   繁体   中英

How to get path of project using custom user control in c#

I created custom user control in WinForms, now I want to get path of project when I drag and drop custom user control to form of new project.

Example: string path = UserControl1.ProjectPath; .

What is the best way to do that?

You can use System.Reflection and the CodeBase of the assembly

var path = Path.GetDirectoryName(typeof(UserControl1).Assembly.CodeBase);

This will give you the folder that contains the DLL; which may or may not be in your project.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM