Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8357027
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:21:29+00:00 2026-06-09T10:21:29+00:00

I have this code that takes a file path that is obtained with the

  • 0

I have this code that takes a file path that is obtained with the OpenFileDialog and attempts to save it to an xml file. For some reason the xml doc will not get written if one of the nodes contains a string from this open file dialog. An exception will not get thrown and the app will not crash, just the file will not get written.

If I use a string literal in place of the m_strSoundFile with the same contents, the xml document will get written correctly. So it has nothing to do with the ‘\’ character being illegal, which is what I initially thought. Maybe it has something to do with the fact that the OpenFileDialog is Win32? Any help would be appreciated.

Thanks,
Alex

/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
    string m_strSoundFile;

    public MainWindow()
    {
        InitializeComponent();
    }

    private void btnChooseFile_Click(object sender, RoutedEventArgs e)
    {
        Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
        dlg.Filter = "Wav files (*.wav)|*.wav"; // Filter files by extension
        dlg.InitialDirectory = @"C:\windows\media";

        Nullable<bool> result = true;
        bool pathExists = false;
        do
        {
            result = dlg.ShowDialog();

            if (result == true)
            {
                pathExists = dlg.CheckPathExists;
                if (!pathExists)
                    MessageBox.Show("Path does not exist");
                else
                    m_strSoundFile = dlg.FileName;
            }

        } while (result == true && !pathExists);

        m_tbFilename.Text = m_strSoundFile;
    }

    private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
    {
        XmlDocument xmlDoc = new XmlDocument();
        XmlNode xmlRootNode = xmlDoc.CreateElement("Settings");

        XmlNode node = xmlDoc.CreateElement("File");
        XmlAttribute a = xmlDoc.CreateAttribute("Path");
        a.Value = m_strSoundFile;

        node.Attributes.Append(a);

        xmlRootNode.AppendChild(node);
        xmlDoc.AppendChild(xmlRootNode);

        System.IO.FileStream fs;
        try
        {
            fs = System.IO.File.Open("configfile.xml", System.IO.FileMode.Create, System.IO.FileAccess.Write);
            xmlDoc.Save(XmlWriter.Create(fs, new XmlWriterSettings() { Indent = true, Encoding = Encoding.UTF8 }));
            fs.Close();
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T10:21:31+00:00Added an answer on June 9, 2026 at 10:21 am

    Ok, I figured it out. After using an absolute path for the filestream it worked. It’s still weird that it works conditionally when not using an absolute path.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code that reads from XML file. It gets five strings (groupId,
I have this small piece of code that basically takes a list and runs
I have this code that fetches some text from a page using BeautifulSoup soup=
I have this applescript that takes the selected item and zips that file/folder and
I have a parser function written in my code-behind file, that takes as input
I have this code that I've edited: http://pastebin.com/vrqHek6S I've put in comments where I
I have this code that runs but never stops. class A { public static
I have this code that suppose to place the marker by the latlng public
I have this code that where I would normally use one line: if (tableView
I have this code that works in a unit test but doesn't work when

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.