none
save a windows form file RRS feed

  • Question

  • I've searched the web - most use the savefiledialog and streamwriter commands however I don't seem able to achieve it.

    I'm running visual studio 2017. Am I missing something?

    I receive an Exception error on the streamwriter line

            private void CloseMenu_Click(object sender, EventArgs e)
            {
                SaveFileDialog save = new SaveFileDialog();
                StreamWriter write = new StreamWriter(File.Create(save.FileName));
               
    
                write.Write(RSMtext.Text);
                write.Write(PARTStext.Text);
                write.Write(ENGINEERINGtext.Text);
                write.Write(SERVICEtext.Text);
                write.Write(JUNKtext.Text);
                write.Write(TROYCtext.Text);
                write.Write(SOUTHAFRICAtext.Text);
                write.Write(HEATHERStext.Text);
                write.Write(SHIPPINGtext.Text);
                write.Write(DELIVERYtext.Text);
                write.Write(OTHERtext.Text);
                write.Write(RETURN2CUSTOMERtext.Text);
    
    
                write.Write(RSMtotal.Text);
                write.Write(PARTStotal.Text);
                write.Write(ENGINEERINGtotal.Text);
                write.Write(SERVICEtotal.Text);
                write.Write(JUNKtotal.Text);
                write.Write(TROYCtotal.Text);
                write.Write(SOUTHAFRICAtotal.Text);
                write.Write(HEATHERStotal.Text);
                write.Write(SHIPPINGtotal.Text);
                write.Write(DELIVERYtotal.Text);
                write.Write(OTHERtotal.Text);
                write.Write(RETURN2CUSTOMERtotal.Text);
    
                write.Dispose();
            }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    


    tac

    Sunday, August 5, 2018 8:40 PM

All replies

  • Hi Troy22222,

    Thank you for posting here.

    For your question, do you want to save the text to .txt file? If yes, please try the code below. You could save to a new file or a file exists.

       SaveFileDialog save = new SaveFileDialog();
                save.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
                save.Title = "Save TEXT TO File";
                save.ShowDialog();
    
                StreamWriter write = new StreamWriter(File.Create(save.FileName));
                write.Write(textBox2.Text);  
    
                write.Dispose();

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Monday, August 6, 2018 6:09 AM
    Moderator
  • cheong00:

    Thanks for your response, I'm sure it would work however I've found a better/quicker way to solve my particular issue.

    tac


    tac

    Friday, August 10, 2018 5:46 PM
  • Wendy:

    Thanks for your response, I'm sure it would work however I've found a better/quicker way to solve my particular issue.

    tac


    tac

    Friday, August 10, 2018 5:47 PM
  • Thanks for your response, I'm sure it would work however I've found a better/quicker way to solve my particular issue.


    Troy -- Could you post what you've found that works better? Others searching this Forums might be interested in what you came up with ...

    ~~Bonnie DeWitt [C# MVP]

    http://geek-goddess-bonnie.blogspot.com

    Saturday, August 11, 2018 5:02 AM
    Moderator