Post: C# How to Open and Save
10-30-2011, 07:44 PM #1
Pichu
RIP PICHU.
(adsbygoogle = window.adsbygoogle || []).push({}); How to open and save.

Difficulty [][][][][][][][][][] [1/10]

----------------------------------

You will need to create a new form and create the following:
2 Buttons (Name one "Open" and the other "Save"
1 TextBox (Select Mutliline)
SaveFileDialog
OpenFileDialog
label1 (<Name it FilePath and set it to invisible).

Place them how you please. An example of how mine is setup:

You must login or register to view this content.

Double click on the two buttons (Save, Open)
Add "Using System.IO"

It should look like this now:

    using System;using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;


namespace CSharp_Open_and_Save
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}


private void save_Click(object sender, EventArgs e)
{


}


private void open_Click(object sender, EventArgs e)
{


}
}
}


To save the text add the following code:

    [FONT=Consolas]if (saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)[/FONT][LEFT][FONT=Consolas]    {[/FONT]
[FONT=Consolas] File.WriteAllText(saveFileDialog1.FileName, textBox1.Text);[/FONT][/LEFT]
[FONT=Consolas] }[/FONT]


To open and search for the text add the following code:

    [FONT=Consolas]if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)[/FONT][LEFT][FONT=Consolas]    {
label1.Text = openFileDialog1.FileName;[/FONT]
[FONT=Consolas] textBox1.Text = File.ReadAllText(label1.Text);[/FONT][/LEFT]
[FONT=Consolas] }[/FONT]


Now note, when you go to save the text you will see this:

You must login or register to view this content.

Go to SaveFileDialog and change filter to:
(*.txt)|*.txt|All files (*.*)|*.*

This will mean that when you now save it will give the option of .txt or All Files

You must login or register to view this content.

Now you may do the same for OpenFileDialog to get the same results for searching

That is it.

Download the source:
You must login or register to view this content.
(adsbygoogle = window.adsbygoogle || []).push({});

The following 3 users say thank you to Pichu for this useful post:

Chrom3D, Epic?, T_m_b07
12-19-2011, 10:54 PM #11
Chrom3D
Big Sister
Originally posted by Sublimity View Post
Happy

I'm thinking I'm just going to stay with C# for now. I'm going to be learning Java in Computer Science next year when I go to college so I think I'll just further learn what I am learning right now. :P

If I can find someone to sell me two 512mb sticks of ram or one 1gb stick of ram to slip into my pc I would be able to start working on XNA like I want to but I can't. :(

---
May consider though learning C++, take what I learn and maybe make some mods for games, older games but a mod lol.

May consider something for pokemon games, open up the file and finds the players bag, pokemon, pokedex and PC pokemon and then allows modification of it to your liking as well as the stats of the pokemon. I don't think something as easy as that has been made so that would be a fun project for if I learn C++.



How much RAM do you have as of now?

I don't think the step from C# to either Java or C++ is that high once you've learned it. That's what I've been told atleast. I will probably go with Java to get use of the book I bought last year. It was like a 80 $ investment or something, and I haven't got used of it since.

Mods for games is probably a good way to go. You learn as you have fun, and it's not too much at a time (I belive).

How old are you btw?
12-19-2011, 11:01 PM #12
Pichu
RIP PICHU.
Originally posted by Chrom3D View Post
How much RAM do you have as of now?

I don't think the step from C# to either Java or C++ is that high once you've learned it. That's what I've been told atleast. I will probably go with Java to get use of the book I bought last year. It was like a 80 $ investment or something, and I haven't got used of it since.

Mods for games is probably a good way to go. You learn as you have fun, and it's not too much at a time (I belive).

How old are you btw?


Well yea, I look at C++ and just need to find a tutorial that can teach me what the hell >> and such is, once I figure that out then I am sure I can pick up what I know of C# and make a full conversion.

Just thinking I should wait until college and learn Java then since I will be paying a load of cash for the Com Science classes.

Mods can take a while or can be fast, depends on the game really. The games I will make mods for won't be new games as I don't have a computer that can handle them, it would be for older games, 1990's - 2002 at latest. My computer has 512mb of ram. Intel Pentium Medion 2.39ghz with 512mb of ram.

I'm 17 years old by about 4 months now... I started learning C# in August, I knew some VB.Net but essentially what was in my Black Ops calculator was all that I knew, now I know a crap load more. :P
12-19-2011, 11:10 PM #13
Chrom3D
Big Sister
Originally posted by Sublimity View Post
Well yea, I look at C++ and just need to find a tutorial that can teach me what the hell >> and such is, once I figure that out then I am sure I can pick up what I know of C# and make a full conversion.

Just thinking I should wait until college and learn Java then since I will be paying a load of cash for the Com Science classes.

Mods can take a while or can be fast, depends on the game really. The games I will make mods for won't be new games as I don't have a computer that can handle them, it would be for older games, 1990's - 2002 at latest. My computer has 512mb of ram. Intel Pentium Medion 2.39ghz with 512mb of ram.

I'm 17 years old by about 4 months now... I started learning C# in August, I knew some VB.Net but essentially what was in my Black Ops calculator was all that I knew, now I know a crap load more. :P


Ahh The one I am using has 4 gb RAM, AMD Athlon II X2 215 - 2,70 ghz. I have an old computer with 512 MB DDR RAM card, but the computer itself doesent work. (The HDD is damaged). It was good for it's time, but not now. It was bought for 3.3 K $ in its time, but thats along time ago. I can't remember the processor, but around 2.93 ghz also i think

I am 16 years old btw, and about 3 months year old.
12-19-2011, 11:14 PM #14
Pichu
RIP PICHU.
Originally posted by Chrom3D View Post
Ahh The one I am using has 4 gb RAM, AMD Athlon II X2 215 - 2,70 ghz. I have an old computer with 512 MB DDR RAM card, but the computer itself doesent work. (The HDD is damaged). It was good for it's time, but not now. It was bought for 3.3 K $ in its time, but thats along time ago. I can't remember the processor, but around 2.93 ghz also i think

I am 16 years old btw, and about 3 months year old.


Well for college, I know that I will be getting a laptop, I don't know what it's specs will be or anything but I know we will be going with an I7 processor.

It will be more than enough to support what I want though, I mean if what I do on this computer pushes it to the edge then what I do on that won't be a problem at all. Happy

Copyright © 2026, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo