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 7903843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:50:54+00:00 2026-06-03T09:50:54+00:00

im stuck with this stupid form… heres my code. It saves it where the

  • 0

im stuck with this stupid form… heres my code. It saves it where the streamwriter wants it to but when i save it where the user wants via the savedialog box is creates the XML but doesnt put anything in it! Can someone have a look as it’s starting to wind me up!

void SavebuttonClick(object sender, EventArgs e)
{
    Stream myStream ;
    SaveFileDialog savefile1 = new SaveFileDialog();

    savefile1.Filter = "xml files |*.xml"  ;
    savefile1.FilterIndex = 2 ;
    savefile1.RestoreDirectory = true ;

    if(savefile1.ShowDialog() == DialogResult.OK)
    {
        if((myStream = savefile1.OpenFile()) != null)
        {
            Values v = new Values();
            v.task1_name = this.task1_name.Text;
            v.task1_desc = this.task1_desc.Text;
            v.task1_date = this.task1_date.Value;
            v.task1_time = this.task1_time.Value;
            SaveValues(v);
        }
        myStream.Close();   
    }
}

This is the streamwriter…

public void SaveValues(Values v)
{
    XmlSerializer serializer = new XmlSerializer(typeof(Values));
    using(TextWriter textWriter = new StreamWriter(@"E:\TheFileYouWantToStore.xml"))
    {
        serializer.Serialize(textWriter, v);
    }
...
}

EDIT:

public class Values 
{
public string task1_name { get; set;}
public string task1_desc { get; set;}
public DateTime task1_date { get; set;}
public DateTime task1_time { get; set;}
}

I presume this is the code you meant, im fairly new to coding though mate 🙁

  • 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-03T09:50:56+00:00Added an answer on June 3, 2026 at 9:50 am

    You must call textWriter.close(); after serialize. If you don’t close writer it won’t apply chenges to file.
    By the way you are writing values to E:\TheFileYouWantToStore.xml. your save save method does not use users file.

    public void SaveValues(Values v)
    {
        XmlSerializer serializer = new XmlSerializer(typeof(Values));
        using(TextWriter textWriter = new StreamWriter(@"E:\TheFileYouWantToStore.xml"))
        {
            serializer.Serialize(textWriter, v);
            textWriter.close();
        }
    ...
    }
    

    EDIT:

    if(savefile1.ShowDialog() == DialogResult.OK)
    {
            Values v = new Values();
            v.task1_name = this.task1_name.Text;
            v.task1_desc = this.task1_desc.Text;
            v.task1_date = this.task1_date.Value;
            v.task1_time = this.task1_time.Value;
            SaveValues(savefile1.FileName, v);
    }
    

    –

    public void SaveValues(string fileName, Values v)
    {
        XmlSerializer serializer = new XmlSerializer(typeof(Values));
        using(TextWriter textWriter = new StreamWriter(fileName))
        {
            serializer.Serialize(textWriter, v);
            textWriter.close();
        }
    ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'dbuser1'@'localhost This is probably something stupid, but
I'm stuck with this kinda stupid problem. I saw examples of my problem, but
Hi guys i'm almost done writing my code and i'm stuck with this stupid
I fear that this is a really stupid question but I am really stuck
I know, maybe this question is stupid but I am stuck and I need
This might be a stupid question, but i'm stuck doing it :(. I have
Im stuck with this little project in C# but basically my problem is this:
I'm stuck with this. I'm self studying assenbler and translating some basics instructions. But
Sorry if the question is stupid but I'm newbie to MySQL and got stuck
This is so stupid. I've been stuck literally for an hour trying to read

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.