Post: [C#] Creating, Reading and Starting Files in Form
06-13-2011, 10:41 PM #1
Correy
I'm the Original
(adsbygoogle = window.adsbygoogle || []).push({}); i've had a few request from this from others, not just from this forum but i figured it will come useful.
all this coding will happen inside a Form, e.g. by the click off a button.

before we start, on every Form you are inluding this in you will need to add the following..


    
using System.IO;


right, now lets get started.

[multipage=Creating A File ]
Creating A File
add this to where ever you want, on a button or what ever.
    
StreamWriter SW = new StreamWriter(@"NextGenUpdate.txt", true);

you need to include the file format, as you can see i'm using the .txt which is a text file, you can add any format but you just need to know what to put at the end.

Now here's a little Add-on which i always do, what it does if there's a file already the it will delete it, i've simplified this but you can edit it and add message boxe's to say Overwrite ? ect.
    
if (File.Exists(@"NextGenUpdate.txt"))
{
File.Delete(@"GPAD0_MP.PRF");
StreamWriter SW = new StreamWriter(@"NextGenUpdate.txt", true);
//MessageBox to show were it's been saved.
MessageBox.Show("File has Been successfully Created\n Saved To :" + Application.StartupPath)
}
else
{ StreamWriter SW = new StreamWriter(@"NextGenUpdate.txt", true); }


so, that should of Created a Text file into the Application Start Up Path

[multipage=Reading and Writing A File ]
add this Code to a button or whatever, this is a set folder.. so if you creating for a certian file this part will show you, i will be using..

TextBox : textEditorControl1
Settings : Settings.Default.SettingName
Timer : timer1

to start, add this code a the top. note, it will need editing
    
using [COLOR="red"]TestForm[/COLOR].Properties;

change the TestForm to you Program Name

this will creat the percific file and inject text into it, add it someone where in the Form
    
InjectText()
{
StreamWriter SW = new StreamWriter(@"Tutorial.txt", true);
SW.Write(Settings.Default.SettingName);
SW.Close();
}


so, that declares that it will write what ever is the Setting, the Setting will be what is in The textBox.
you will need to go to properties and add the textBox_change Code, then add this.
    
{
timer1.Start();
Settings.Default.SettingName = textEditorControl1.Text;
InjectText();
}

so, thats done.
that should now update every time you time something into that text box, no need for a save button.

[multipage=Starting Up Application or Files ]
this is a small, easy but usefull code.
it allows you to open a percific file, i do this for opening an attatchment to my program.

now, you can either do it from the application start up patch which is not in a folder or within the application start up patch inside a folder.

not inside a folder
    
System.Diagnostics.Process.Start("C://" + Application.StartupPath + "/FILENAME.FORMAT");


this code will open a File inside a folder
    
System.Diagnostics.Process.Start("C://" + Application.StartupPath + "/FOLDER/FILENAME.FORMAT");


see, thats easy right ?
Last edited by Correy ; 06-14-2011 at 12:44 AM.

The following user groaned Correy for this awful post:

Epic?
06-17-2011, 07:10 AM #11
kiwimoosical
Bounty hunter
Originally posted by xCorrey
call of duty mod tools, anything like that ?


Google RTCoD, Kiwimoosical Black Ops XEX Patcher, Kiwimoosical RSA Check Remover. I used to.

The following user thanked kiwimoosical for this useful post:

XxprokillahxX
06-17-2011, 01:47 PM #12
Originally posted by kiwimoosical View Post
Google RTCoD, Kiwimoosical Black Ops XEX Patcher, Kiwimoosical RSA Check Remover. I used to.


Legend. Nothing more to say

Haha, I enjoyed all your mw2 stuff as well, great work back then!
06-17-2011, 01:50 PM #13
Correy
I'm the Original
Originally posted by kiwimoosical View Post
Google RTCoD, Kiwimoosical Black Ops XEX Patcher, Kiwimoosical RSA Check Remover. I used to.


nice, some good programmin there.. i have a question for you.
you know the move files code, how would i move the file in the application start up to a folder in the startup path ?
06-17-2011, 04:44 PM #14
Epic?
Awe-Inspiring
Originally posted by fill0botto95 View Post
the second....in C# express 2010 i can't find this option


His code alone won't really do anything, so you have to put his functionality behind a GUI or something. Then, you can simply hit the green "Play" button, or go into Debug the debug tab and then press Start Debugging.

To turn it into a standalone program, go into the Project tab, and then click Publish. After that, you're program will have been published into an executable. You can find the single executable in your project file:
Visual Studio 2010 > Projects > *your project* > bin > Release


To build a program in C# that can create other programs is much more complicated.

The following 2 users say thank you to Epic? for this useful post:

Correy, fill0botto95
06-17-2011, 04:55 PM #15
fill0botto95
You talkin to me?
Originally posted by AsianInvasion View Post

To build a program in C# that can create other programs is much more complicated.


i think so lol
anyway i sometimes use vb 2006 to build some exe...
06-18-2011, 08:48 PM #16
Correy
I'm the Original
Originally posted by fill0botto95 View Post
is there a way to build the exe?


you need to rename the .bilog.exe (something like that), just remove the .bilog part
06-20-2011, 02:50 AM #17
kiwimoosical
Bounty hunter
Originally posted by xCorrey
nice, some good programmin there.. i have a question for you.
you know the move files code, how would i move the file in the application start up to a folder in the startup path ?


    File.Move(Application.StartupPath + "www.exe", Application.StartupPath + "folder\\www.exe");

The following user thanked kiwimoosical for this useful post:

Correy
06-20-2011, 08:37 AM #18
kiwimoosical
Bounty hunter
Originally posted by XxprokillahxX View Post
Legend. Nothing more to say

Haha, I enjoyed all your mw2 stuff as well, great work back then!


Thanks man! Good time :P

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo