Generate a C # form application in two modes: Release and Debug. The relative path difference between reading and writing files

Source: Internet
Author: User
I always feel that the question is a bit awkward, but I don't know if it is due to the difference between the two compilation modes, so I can only use this long and obscure question.
When creating some applications, we often use XML files to store some program configuration information, or even a small amount of data information, and sometimes provide end users with the ability to edit the information, users' edits should also be permanently saved in the XML file. Take the C # windows form program as an example.
In my program, the project executable file is generated in debug mode, and the XML file to be read and written is saved in the directory of bin \ debug \.
Doc. load ("sourcefile. XML "); get the xmldocument object doc, and then edit the doc object accordingly. After the editing is complete, use Doc. save ("sourcefile. XML "); Save the XML file, which has no problem. The next time you start the generated executable file and load the XML file, you can see that the XML file has been updated.
Then generate the executable file in the release mode. The other operations are identical to those in the debug mode. load ("sourcefile. XML "); Doc. save ("sourcefile. XML "); the results of the two statements are very different. The sourcefile is used to start the executable program and load the XML file for the second time. XML has not changed, and a temporary file is generated under the "C: \ Documents and Settings \ haoxiangshan \ Desktop" directory on my desktop, this file stores the user's changes.
After some searching and pondering, I feel that the relative path of the file is incorrect, or the difference between release and debug is also reflected in one aspect (I have not figured out the principle, ), in the article example ("sourcefile. XML "); Doc. save ("sourcefile. XML "); changed to Doc. load (appdomain. currentdomain. basedirectory + "sourcefile. XML "); Doc. save (appdomain. currentdomain. basedirectory + "sourcefile. XML "); the problem is solved, and the results obtained in debug and release are exactly the same.
Conclusion: I have seen a lot of differences between release and Debug on the Internet, but I don't understand what is going on. However, I think this problem mentioned in this article really requires attention in development, I used to finish the program in debug mode. This time I used release to find that I had never done a complete program before! Haha, sorry...
Related Article

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.