Hi
friends, in this article I will explain about how to save the data in notepad in VB.NET or C# windows forms and how to create notepad file or how to append the data
to existing notepad file in VB.NET or C# windows forms.
First of all, take one windows form.
File—New—Project or Ctrl+Shift+N
Then take the 2 textboxes , 2 labels and 1 button in the below figure.
Then take the 2 textboxes , 2 labels and 1 button in the below figure.
Then write the following code in the button click.
VB.NET
Imports System.IO
Public Class Form1
Private Sub Button1_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim
swriter As StreamWriter
swriter = File.AppendText("c:\temp\myfile.txt")
swriter.WriteLine(TextBox1.Text &
" " & TextBox2.Text)
swriter.Close()
End Sub
End Class
|
C#.NET
using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.IO;
Public Class Form1
{
private
void Button1_Click(System.Object sender, System.EventArgs e)
{
StreamWriter swriter = null;
swriter = File.AppendText("c:\\temp\\myfile.txt");
swriter.WriteLine(TextBox1.Text + " " + TextBox2.Text);
swriter.Close();
}
}
|
We have imports the System.IO namespace otherwise it will raise
error.
"If you like my blog or articles, you can appreciate by leaving your comments or Liking my Facebook page Aspdotnet-kishore, following on Google+ Aspdotnet-Kishore, Twitter on AspdotnetKishore, Linked in Aspdotnet-Kishore, stumbling my posts on stumble upon and subscribing on RSSfeed Aspdotnet-Kishore for free updates directly to your Email inbox . Watch my blog for more articles"
No comments:
Post a Comment