Writing Text box Inputs to Text File

Writing and Formatting Inputs from Multiple Text Boxes

Page 1 of 1

14 Replies - 26316 Views - Last Post: 12 September 2008 - 03:46 AM Rate Topic: -----

#1 gram999   User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 89
  • Joined: 21-January 08

Writing Text box Inputs to Text File

Posted 06 February 2008 - 11:43 AM

I am trying to get multiple textbox inputs to write to a text file in a specific format. When the user inputs data into the text box and clicks the command button I want the information to be transferred to a text file under specific headings. I have the headings worked out somewhat and was trying a loop for writing the text box info but I am running into a couple of issues:

1) I have not been able to figure out how to assign the
text box entries positions under the headings in the txt file ({0,1}{1,3} etc...

2) Is there any way of just writing the headings into the text file once and then having the information below them like this:


Area Cited (space) Possible Points (space) Points Appealable
Kitchen (space) 8.0 (space) 5.0


All suggestions and ideas are welcome. Thanks!

Dim File_Name As String = "C:\testreport.txt"
		Dim i As Integer
		Dim aryText(5) As String

		Dim objWriter As New System.IO.StreamWriter(File_Name, True)

		'Inserts column headings into text file
		objWriter.WriteLine("{0,1}{1,3}{2,24}{3,14}{4,20}{5,26}", "Area Cited", "", "Possible Points for Area", "Points Cited", "Points Appealable", "Possible Points Returned")

		'Inserts textbox data into .txt file

		aryText(1) = Me.txtDEArea.Text
		aryText(2) = Me.txtDEPossPoints.Text
		aryText(3) = Me.txtDEPointCited.Text
		aryText(4) = Me.txtDETotalPtsApp.Text
		aryText(5) = iPPR

		For i = 0 To 5

			objWriter.WriteLine(aryText(i))

		Next

		objWriter.Close()

'Clear all textboxes

		Me.txtDEArea.Clear()
		Me.txtDEPossPoints.Clear()
		Me.txtDEPointCited.Clear()
		Me.txtDETotalPtsApp.Clear()
		Me.txtDEArea.Focus()


		strNote = "Do you have another item to add?"

		strYNBx = MsgBox(strNote, vbQuestion + vbYesNo, "Add an Item?")

		If strYNBx = vbNo Then
			'Code for No button Press
			Me.Hide()

		Else
			'Code for Yes button Press
			Me.txtDEArea.Focus()

		End If
		Exit Sub



This post has been edited by gram999: 06 February 2008 - 11:45 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Writing Text box Inputs to Text File

#2 scalt   User is offline

  • D.I.C Regular
  • member icon

Reputation: 63
  • View blog
  • Posts: 344
  • Joined: 22-November 07

Re: Writing Text box Inputs to Text File

Posted 07 February 2008 - 03:38 PM

One way of writing first the headings, then the data would be to add the contents of the text boxes to a big array every time the 'OK' button is clicked, then write the whole thing to your file when the user has finished. However, because the basic array in VB.NET is fixed size it is easier to use several 'ArrayLists' - essentially a dynamic, 1-D array.

	Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
		
		'declare arraylists
		Dim alstTxt1, alstTxt2, alstTxt3, alstTxt4, alstTxt4 As New ArrayList

		Dim i As Integer
		Dim strNote As String
		Dim FileName As String = "C:\testreport.txt"
		Dim objWriter As New System.IO.StreamWriter(FileName, True)
	  
		'add text boxes to arrays
		alstTxt1.Add(Me.txtDEArea.Text) 
		alstTxt2.Add(Me.txtDEPossPoints.Text
		alstTxt3.Add(Me.txtDEPointCited.Text
		alstTxt4.Add(Me.txtDETotalPtsApp.Text
		alstTxt(5).Add(iPPR)

		'clear text boxes
		Me.txtDEArea.Clear()
		Me.txtDEPossPoints.Clear()
		Me.txtDEPointCited.Clear()
		Me.txtDETotalPtsApp.Clear()
		Me.txtDEArea.Focus()

		strNote = "Do you have another item to add?"

		strYNBx = MsgBox(strNote, vbQuestion + vbYesNo, "Add an Item?")

		If strYNBx = vbNo Then
			'if no more data, write file

			'write headings
			objWriter.WriteLine('HEADING TEXT GOES HERE')

			'write data to file
			For i = 0 To alstBox1.Count - 1
				objWriter.WriteLine(alstBox1(i) + " " + alstBox2(i) + " " + alstBox3(i) + " " + alstBox4(i))
			Next
		
			'close streamwriter			
			objWriter.Close()
		
			Me.Hide()
		Else
			'else, keep going

			Me.txtDEArea.Focus()

		End If

	End Sub



Essentially this just re-orders your original code, as well as changes the way you store the text box text.

Does that answer your question?

This post has been edited by scalt: 07 February 2008 - 03:41 PM

Was This Post Helpful? 0
  • +
  • -

#3 gram999   User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 89
  • Joined: 21-January 08

Re: Writing Text box Inputs to Text File

Posted 09 February 2008 - 10:17 AM

Thanks sUPER cOOL Salt! You nailed it! This looks great. You made my weekend. Have a good one. Thanks again.
Was This Post Helpful? 0
  • +
  • -

#4 gram999   User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 89
  • Joined: 21-January 08

Re: Writing Text box Inputs to Text File

Posted 11 February 2008 - 02:13 PM

I am still having a problem with this one. It is giving me the following error: Conversion from string "TEXT 5.0 5.0 5.0" to type 'Double' is not valid. Parameter name: Index" Here is the line of code it is hanging on:

objWriter.WriteLine(alstTxt1(i) + alstTxt2(i) + " " + alstTxt3(i) + " " + alstTxt4(i) + "" + alstTxt5(i))
Note: The 5.0, 5.0, 5.0 is the data that was entered into the textboxs when I was debugging.  It could be any number not just 5.0

Here is the whole thing:



'Converts the Possible Point Total to Integer
		iPP = CInt(txtDEPossPoints.Text.Trim)
		iPC = CInt(txtDEPointCited.Text.Trim)
		iPA = CInt(txtDETotalPtsApp.Text.Trim)

		If iPC > iPP Then iPPR = ((iPP - iPC) + iPA)

		If iPC <= iPP Then iPPR = iPA



		'Add Copy Data to Sheet Here:

		
		'declare arraylists
		Dim alstTxt1, alstTxt2, alstTxt3, alstTxt4, alstTxt5 As New ArrayList
		Dim i As Integer
		Dim FileName As String = "C:\testreport.txt"
		Dim objWriter As New System.IO.StreamWriter(FileName, True)

		'add text boxes to arrays
		alstTxt1.Add(Me.txtDEArea.Text)
		alstTxt2.Add(Me.txtDEPossPoints.Text)
		alstTxt3.Add(Me.txtDEPointCited.Text)
		alstTxt4.Add(Me.txtDETotalPtsApp.Text)
		alstTxt5.Add(iPPR)

		'clear text boxes
		Me.txtDEArea.Clear()
		Me.txtDEPossPoints.Clear()
		Me.txtDEPointCited.Clear()
		Me.txtDETotalPtsApp.Clear()
		Me.txtDEArea.Focus()

		strNote = "Do you have another item to add?"

		strYNBx = MsgBox(strNote, vbQuestion + vbYesNo, "Add an Item?")

		If strYNBx = vbNo Then
			'if no more data, write file

			'write headings
			objWriter.WriteLine("{0,1}{1,3}{2,24}{3,14}{4,20}{5,26}", "Area Cited", "", "Possible Points for Area", "Points Cited", "Points Appealable", "Possible Points Returned")

			'write data to file
			For i = 0 To alstTxt1.Count - 1
				objWriter.WriteLine(alstTxt1(i) + alstTxt2(i) + " " + alstTxt3(i) + " " + alstTxt4(i) + "" + alstTxt5(i))
			Next

			'close streamwriter			
			objWriter.Close()

			Me.Hide()
		Else
			'else, keep going

			Me.txtDEArea.Focus()

		End If




iPPR can be a negative number. I tried changing the conversion from CInt to CDec but still get errors on this line.

This post has been edited by gram999: 11 February 2008 - 03:47 PM

Was This Post Helpful? 0
  • +
  • -

#5 scalt   User is offline

  • D.I.C Regular
  • member icon

Reputation: 63
  • View blog
  • Posts: 344
  • Joined: 22-November 07

Re: Writing Text box Inputs to Text File

Posted 12 February 2008 - 01:36 PM

Ok, your problem here is caused by alstTxt5. When you are adding iPP to the ArrayList it is adding it as an integer (or decimal or whatever you end up declaring iPP as). Thus, when your code goes to add alstTxt5 to the WriteStream, which is a string, it tries to use a methematical operation rather than putting it on the end.

ie
"This is a string" + 5 = ERROR

"This is a string" + "5" = "This is a string5"


To get around this you have to convert either iPP or alstTxt5(i) to a string before it is added to either the ArrayList or the WriteStream string respectively. If you are NOT intending to do anything mathematical with alstTxt5 (ie no summing/averageing etc) then simply change

alstTxt5.Add(iPPR)

'to

alstTxt5.Add(CStr(iPPR))



Note: CStr converts the value of the current variable to a string

If, however, you still want to be able to access elements of alstTxt5 as numbers then change

objWriter.WriteLine(alstTxt1(i) + alstTxt2(i) + " " + alstTxt3(i) + " " + alstTxt4(i) + "" + alstTxt5(i))

'to

objWriter.WriteLine(alstTxt1(i) + alstTxt2(i) + " " + alstTxt3(i) + " " + alstTxt4(i) + "" + CStr(alstTxt5(i)))



In short, if you are trying to add a number into a string, you must use CStr(number) to first convert the number to a string so it can be added.

Hope this helps

This post has been edited by scalt: 12 February 2008 - 01:37 PM

Was This Post Helpful? 0
  • +
  • -

#6 gram999   User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 89
  • Joined: 21-January 08

Re: Writing Text box Inputs to Text File

Posted 12 February 2008 - 03:54 PM

Thanks SCS (especially for the explanation). I figured that it was a declaration problem but I could not figure out if it was due to the conversion declaration on the variables or on the arrays. Thanks for showing me how to convert the array. Greatly appreciated. I am certain that I will be using that information again. Have a good evening.
Was This Post Helpful? 0
  • +
  • -

#7 priyashe   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 74
  • Joined: 28-August 08

Re: Writing Text box Inputs to Text File

Posted 10 September 2008 - 02:23 AM

i too want to perform the task as above but instead of multiple textbox i'm using single text box but in that i have to giv an 16 digit variables wit delimiter (;)ie23;23;23;23;23;23;23;23;23;23;23;23;23;23;23;23 each digit denotes specific item first 23 denotes item second denotes name and i have to save it in to the text file with headings fo example:

item no code rate ....
23 23 23 23

is it possible

plz do reply

i too want to perform the task as above but instead of multiple textbox i'm using single text box but in that i have to giv an 16 digit variables wit delimiter (;)ie23;23;23;23;23;23;23;23;23;23;23;23;23;23;23;23 each digit denotes specific item first 23 denotes item second denotes name and i have to save it in to the text file with headings fo example:

item no code rate ....
23 23 23 23

is it possible

plz do reply
Was This Post Helpful? 0
  • +
  • -

#8 scalt   User is offline

  • D.I.C Regular
  • member icon

Reputation: 63
  • View blog
  • Posts: 344
  • Joined: 22-November 07

Re: Writing Text box Inputs to Text File

Posted 10 September 2008 - 03:27 AM

Hi,
Do you need to add the numbers into arrays first? It sounds like you could probably just get away with replacing the ";" delimiter with tabs using
		Replace(vars, ";", vbTab)


Personally I would use tabs because then you can get everything to line up with the headings nicely (note that I have used tabs to separate the headings when I put them into the string). If you want to use spaces then simply separate the headings with spaces, then use " " instead of vbTab in the 'replace' code. For an example, see the code below (it will put the finished txt file in C:\output.txt)

        'put column headings in here
        Dim headings As String = "item	no	code	rate"
        'text box data here
        Dim vars As String = TextBox.Text
        'open write stream
        Dim writeStream As New System.IO.StreamWriter("C:\output.txt")

        'add tabs to strings (formatting preference)
        vars = Replace(vars, ";", vbTab)

        'write strings to file
        writeStream.WriteLine(headings)
        writeStream.WriteLine(vars)

        'make sure you close the write stream
        writeStream.Close()


This post has been edited by scalt: 10 September 2008 - 03:29 AM

Was This Post Helpful? 0
  • +
  • -

#9 priyashe   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 74
  • Joined: 28-August 08

Re: Writing Text box Inputs to Text File

Posted 10 September 2008 - 04:49 AM

thanks for u'r helps it works file... but once i try to enter datas again to a text file the previously stored datas are getting deleted i want to store datas again and again without deleting previous ..can u plz help
Was This Post Helpful? 0
  • +
  • -

#10 Jayman   User is offline

  • Student of Life
  • member icon

Reputation: 423
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Writing Text box Inputs to Text File

Posted 10 September 2008 - 08:40 AM

If you want to append the data, then set the append attribute to True in the StreamWriter constructor.

Dim writeStream As New System.IO.StreamWriter("C:\output.txt", True)

Was This Post Helpful? 0
  • +
  • -

#11 priyashe   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 74
  • Joined: 28-August 08

Re: Writing Text box Inputs to Text File

Posted 10 September 2008 - 10:41 PM

sorry it's not working same problem arises
Was This Post Helpful? 0
  • +
  • -

#12 scalt   User is offline

  • D.I.C Regular
  • member icon

Reputation: 63
  • View blog
  • Posts: 344
  • Joined: 22-November 07

Re: Writing Text box Inputs to Text File

Posted 11 September 2008 - 02:30 AM

Are you sure you are adding the 'True' part? It works fine for me (just remember that if you don't want to add the headings to the file again you will have to find a way of not writing that string a second time)
Was This Post Helpful? 0
  • +
  • -

#13 priyashe   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 74
  • Joined: 28-August 08

Re: Writing Text box Inputs to Text File

Posted 11 September 2008 - 03:50 AM

k thanx i hav another issue i have done a chat application using 2 pc's and connected by giving ip address of each other i have to open a text file in the machine to which we caht and copy the datas we send is it possible
Was This Post Helpful? 0
  • +
  • -

#14 scalt   User is offline

  • D.I.C Regular
  • member icon

Reputation: 63
  • View blog
  • Posts: 344
  • Joined: 22-November 07

Re: Writing Text box Inputs to Text File

Posted 12 September 2008 - 02:25 AM

like a log file of the chat application? What's your code?

This post has been edited by scalt: 12 September 2008 - 04:04 AM

Was This Post Helpful? 0
  • +
  • -

#15 priyashe   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 74
  • Joined: 28-August 08

Re: Writing Text box Inputs to Text File

Posted 12 September 2008 - 03:46 AM

this is client side code
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.Text;
using System.Diagnostics;
using System.IO;
namespace TcpClientApp
{
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
		private System.Windows.Forms.TextBox textBoxSendText;
		private System.Windows.Forms.Button buttonConnect;
		private TcpClient tcp = null;
		private string ipAddress ="";
		private Thread receiveThread = null;
		private byte [] received = null;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.TextBox textBoxDataToSend;
		private byte[] dataToSend = null;
		private bool formClosing = false;
		private System.Windows.Forms.TextBox textBoxIPAddress;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.Button buttonSend;
		private SaveFileDialog saveFileDialog1;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public Form1()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
			buttonSend.Enabled = false;
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.textBoxSendText = new System.Windows.Forms.TextBox();
			this.buttonConnect = new System.Windows.Forms.Button();
			this.label1 = new System.Windows.Forms.Label();
			this.textBoxDataToSend = new System.Windows.Forms.TextBox();
			this.textBoxIPAddress = new System.Windows.Forms.TextBox();
			this.label3 = new System.Windows.Forms.Label();
			this.buttonSend = new System.Windows.Forms.Button();
			this.saveFileDialog1 = new System.Windows.Forms.SaveFileDialog();
			this.SuspendLayout();
			// 
			// textBoxSendText
			// 
			this.textBoxSendText.Location = new System.Drawing.Point(120, 64);
			this.textBoxSendText.Multiline = true;
			this.textBoxSendText.Name = "textBoxSendText";
			this.textBoxSendText.ReadOnly = true;
			this.textBoxSendText.ScrollBars = System.Windows.Forms.ScrollBars.Both;
			this.textBoxSendText.Size = new System.Drawing.Size(248, 64);
			this.textBoxSendText.TabIndex = 3;
			// 
			// buttonConnect
			// 
			this.buttonConnect.Location = new System.Drawing.Point(248, 8);
			this.buttonConnect.Name = "buttonConnect";
			this.buttonConnect.Size = new System.Drawing.Size(75, 23);
			this.buttonConnect.TabIndex = 1;
			this.buttonConnect.Text = "Connect";
			this.buttonConnect.Click += new System.EventHandler(this.buttonConnect_Click);
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(8, 64);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(100, 24);
			this.label1.TabIndex = 4;
			this.label1.Text = "Incoming Message";
			// 
			// textBoxDataToSend
			// 
			this.textBoxDataToSend.Location = new System.Drawing.Point(120, 160);
			this.textBoxDataToSend.Multiline = true;
			this.textBoxDataToSend.Name = "textBoxDataToSend";
			this.textBoxDataToSend.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
			this.textBoxDataToSend.Size = new System.Drawing.Size(248, 72);
			this.textBoxDataToSend.TabIndex = 2;
			// 
			// textBoxIPAddress
			// 
			this.textBoxIPAddress.Location = new System.Drawing.Point(112, 8);
			this.textBoxIPAddress.Name = "textBoxIPAddress";
			this.textBoxIPAddress.Size = new System.Drawing.Size(100, 20);
			this.textBoxIPAddress.TabIndex = 0;
			this.textBoxIPAddress.TextChanged += new System.EventHandler(this.textBoxIPAddress_TextChanged);
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(8, 8);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(100, 32);
			this.label3.TabIndex = 8;
			this.label3.Text = "IP address of the listener";
			// 
			// buttonSend
			// 
			this.buttonSend.Location = new System.Drawing.Point(192, 248);
			this.buttonSend.Name = "buttonSend";
			this.buttonSend.Size = new System.Drawing.Size(75, 23);
			this.buttonSend.TabIndex = 4;
			this.buttonSend.Text = "Send";
			this.buttonSend.Click += new System.EventHandler(this.buttonSend_Click);
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(384, 309);
			this.Controls.Add(this.buttonSend);
			this.Controls.Add(this.label3);
			this.Controls.Add(this.textBoxIPAddress);
			this.Controls.Add(this.textBoxDataToSend);
			this.Controls.Add(this.textBoxSendText);
			this.Controls.Add(this.label1);
			this.Controls.Add(this.buttonConnect);
			this.Name = "Form1";
			this.Text = "Client";
			this.Load += new System.EventHandler(this.Form1_Load);
			this.Closing += new System.ComponentModel.CancelEventHandler(this.Form1_Closing);
			this.ResumeLayout(false);
			this.PerformLayout();

		}
		#endregion

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new Form1());
		}

		public void ThreadProcReceive()
		{
			for (;;)
			{
				received = new byte[1024];
				int readBytes = 0;

				try
				{
					readBytes = tcp.GetStream().Read(received,0,received.Length);
				}
				catch (ObjectDisposedException)
				{
					return;
				}
				if (readBytes == 8)
				{
					StringBuilder shutMessage = new StringBuilder(8);
					for (int count = 0; count < 8; count++)
					{
						char ch = (char)received[count];
						shutMessage = shutMessage.Append(ch);
					}
					string shut = "shutdown";
					string receivedMessage = shutMessage.ToString();
					if (receivedMessage.Equals(shut))
					{
						MessageBox.Show(this,"Shutdown Request has arrived from the \nconnected party.\nYou cannot send message anymore.\nPlease close the window.","Shut Down Request",MessageBoxButtons.OK,MessageBoxIcon.Information);
						buttonSend.Enabled = false;
						return;
					}
				}
				StringBuilder str = new StringBuilder(1024);
				for (int count = 0; count < readBytes; count++)
				{
					char ch = (char)received[count];
					str = str.Append(ch);
					str = str.Append(" ");
				}
				//textBoxSendText.Text = str.ToString();
				if (formClosing == true)
				{
					break;
				}
			}
		}
		
		private void buttonConnect_Click(object sender, System.EventArgs e)
		{
			textBoxIPAddress.Enabled = false;
			IPAddress address = IPAddress.Parse(ipAddress);
					
			tcp = new TcpClient((new IPEndPoint(Dns.Resolve(Dns.GetHostName()).AddressList[0],4002)));
			LingerOption lingerOption = new LingerOption(false, 1);
			tcp.LingerState = lingerOption;
			tcp.Connect(new IPEndPoint(Dns.Resolve(ipAddress).AddressList[0],81));
			buttonSend.Enabled = true;
			((Button)sender).Enabled = false;
			receiveThread = new Thread(new ThreadStart(ThreadProcReceive));
			receiveThread.Name = "Client's Receive Thread";
			receiveThread.ApartmentState = ApartmentState.MTA;
			receiveThread.Start();
		}

		private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
		{
			dataToSend = new byte[]{(byte)'s',(byte)'h',(byte)'u',(byte)'t',(byte)'d',(byte)'o',(byte)'w',(byte)'n'};
			tcp.GetStream().Write(dataToSend,0,dataToSend.Length);
			tcp.Close();
		}

		private void textBoxIPAddress_TextChanged(object sender, System.EventArgs e)
		{
			ipAddress = textBoxIPAddress.Text;
		}

		private void textBoxPortNumber_TextChanged(object sender, System.EventArgs e)
		{
			
		}

		private void Form1_Load(object sender, System.EventArgs e)
		{
		
		}
		private void buttonSend_Click(object sender, System.EventArgs e)
		{
			if (textBoxDataToSend.Text.Length != 0)
			{
				char[] charArray = textBoxDataToSend.Text.ToCharArray(0,textBoxDataToSend.Text.Length);
				dataToSend = new byte[textBoxDataToSend.Text.Length];
				for (int charCount = 0; 
					charCount < textBoxDataToSend.Text.Length;
					charCount++)
				{
					dataToSend[charCount] = (byte)charArray[charCount];


				}
			}
			else
			{
				dataToSend = new byte[]{(byte)'e',(byte)'m',(byte)'p',(byte)'t',(byte)'y'};
			}

			

			//TextWriter tw = new StreamWriter(@"C:\test.txt");

			//Process.Start(@"C:\test.txt");
			string data = textBoxDataToSend.Text;

			saveFileDialog1.Filter = "Text file | *.txt";

		   saveFileDialog1.ShowDialog();
			if (saveFileDialog1.FileName != "")
			{

				FileStream myFile = (FileStream)saveFileDialog1.OpenFile();

				StreamWriter myStream = new StreamWriter(myFile);

				myStream.Write(textBoxDataToSend .Text);

				myStream.Close();

				myFile.Close();

				tcp.GetStream().Write(dataToSend, 0, dataToSend.Length);
				textBoxDataToSend.Text = "";

			}

			tcp.GetStream().Write(dataToSend,0,dataToSend.Length);
			textBoxDataToSend.Text = "";
		}

		private string Read(string file)
		
		{ 
			
			StreamReader reader = new StreamReader(file);
			
			string data = reader.ReadToEnd();
			
			reader.Close(); 
			
			return data; }
	}
}
 

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1