File loss caused by xmldocument. Save () usage Error

Source: Internet
Author: User

Error environment:

Write some content in the XML document. The entire process is:

First, check whether the XML file is in the current path. If so, use xmldocument. Load () to load the file. If not, create the XML file and save it with xmldocument. Save (string ).

ErrorCodeAs follows:

 
// XML file name m_xmlfilename = "filerecvrecord. XML "; // get the file name (including the full path name) string filefullname = directory. getcurrentdirectory () + @ "\" + m_xmlfilename; // check whether the file contains m_isfileexisted = file. exists (filefullname );

Save the XML file code:

 
M_xmldoc.save (m_xmlfilename );

Error:

The newly created XML file should be in the current directory, but cannot be found

Error cause:

After finding the file, you will find that the newly created XML file is under "My Documents" instead of the current directory.

Later, I thought it might be becauseAn error occurred while using xmldocument. Save ().

After modifying the code, we found that this was the case.

 
Public:Virtual Void Save(String ^Filename)
Parameters Filename Indicates Location of the file to be saved

Because my m_xmlfilename only saves the file name, but does not include the path name, this problem occurs.

Solution error:

Xmldocument. Save (string filename), saved in ParametersFile Name (must contain absolute path)

The modified code is as follows:

// XML file name (including full path name) m_xmlfilename = directory. getcurrentdirectory () + @ "\ filerecvrecord. xml"; // check whether the file exists m_isfileexisted = file. exists (m_xmlfilename );

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.