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

  • Home
  • SEARCH
  • 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 8480295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:15:25+00:00 2026-06-10T19:15:25+00:00

I am displaying a SaveFileDialog and when OK is clicked I am creating new

  • 0

I am displaying a SaveFileDialog and when OK is clicked I am creating new file, writing some default content to it and then attempting to Open it via the OpenFile() method of the SaveFileDialog. However, the moment I call OpenFile() the content of the file are deleted.

SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.Filter = "XML files (*.xml)|*.xml";
saveFileDialog.RestoreDirectory = true;

if (saveFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
    // First Event Creates file and writes default content to it - works ok 
    NewFileCreated( this, new FileCreatedEventArgs() { Template = Template.BBMF, FilePath = saveFileDialog.FileName } );
    // Second Event clears file content as soon as saveFileDialog.OpenFile() called
    FileLoaded( this, new FileLoadedEventArgs() { FileStream = saveFileDialog.OpenFile() } );
}

Can someone explain why this happens and what I need to be doing to successfully Open the newly created file?

  • 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-10T19:15:26+00:00Added an answer on June 10, 2026 at 7:15 pm

    According to MSDN, SaveFileDialog.OpenFile()

    Caution

    For security purposes, this method creates a new file with the
    selected name and opens it with read/write permissions. This can cause
    unintentional loss of data if you select an existing file to save to.
    To save data to an existing file while retaining existing data, use
    the File class to open the file using the file name returned in the
    FileName property.

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

Sidebar

Related Questions

I'm displaying HTML content using a UIWebView and would like some action to occur
My Java application is displaying some odd behaviour, and I'm having trouble finding a
My app is displaying some data in tabular form (400 rows and 7 columns
While displaying a popover controller for a second time (after dismissing it and then
I'm retrieving and displaying the list of text depending on whichever button/catagory is clicked/selected.
When displaying images on our website, we check if the file exists with a
Displaying content’s based on category and tags criteria works well but how should we
When displaying the body of some articles in my site in an rss reader,
We are displaying an epub file on the screen through our application. The file
I'm displaying a MKMapView with MKAnnotations some of which are selected and showing their

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.