Environment path changed openfiledialog

Source: Internet
Author: User

Openfiledialog dialog = new openfiledialog ();

When openfiledialog is enabled, the Environment path is changed, which sometimes causes unexpected problems. For exampleProgramA file or database operation in the path changes the path after openfiledialog, and the target file/database cannot be found.

You can call

Environment. currentdirectory = appdomain. currentdomain. basedirectory. tostring ();

Restore path

 

 

BTW, ref someone else's blog

C # obtain the path of the current application

For Windows and Web applications, the path they run is different, so the key is to determine which program is currently running. So we can use the following code:

String Path = "";
If (system. environment. currentdirectory = appdomain. currentdomain. basedirectory) // Windows applications are equal
{
Path = appdomain. currentdomain. basedirectory;
}
Else
{
Path = appdomain. currentdomain. basedirectory + "bin \";
}

In this way, if we write a class library and use assembly. loadfrom in the class library, because it is a general class library, it may be used in Windows programs or in the web, so the aboveCodeIt is very convenient.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.