Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > .NET Framework > Smart Device Mobile Application Read and Write Text File




Clound SSD Virtual Server

Smart Device Mobile Application Read and Write Text File

 
  Smart Device Mobile Application Read and Write Text File ง่าย ๆ กับ .NET Framework การเขียน Device Application แบบง่าย ๆ สำหรับการ จัดการ Text File จัดเก็บข้อมูล และ อ่านข้อมูลในรูปแบบของ Text File บน Smart Device

จากบทความ
Go to : .NET Smart Device เขียนโปรแกรมบน Smartphone, Pocket PC , Windows CE , Window Mobile 5-6
Go to : Shared Folder or Map Drive in Emulator Smart Device Mobile Application

จะได้เรียนรู้โครงสร้างการทำงานและการเขียนโปรแกรมพื้นฐานกับ Smart Device ที่ทำงานบนอุปกรณ์ประเภท Smart Phone ที่รันบน Windows CE บทความนี้จะเป็น Workshop เกี่ยวกับการรับข้อมูลและการจัดเก็บข้อมูลลงใน Text File รวมทั้งการอ่านข้อมูล Text File ทีได้ถูกจัดเก็บไว้ใน อุปกรณ์ประเภท Smart Phone สำหรับตัวอย่างนี้ จะไม่ได้มีการเชื่อมต่อกับอุปกรณ์จริง แต่จะใช้การรันผ่าน Virtual Emulator ของ .NET Framework ซึ่งอ่านและทำความเข้าใจกับโครงสร้างของ Emulator ได้จากบทความนี้ => พื้นฐาน Emulator

เริ่มต้นจากการสร้าง Project ประเภท Smart Device -> Device Application

Smart Device Mobile Application Read and Write Text File

เริ่มต้นการสร้าง Project


การสร้าง Form

Program.cs
using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace SmartDevice
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [MTAThread]
        static void Main()
        {
            Application.Run(new frmMain());
        }
    }
}


1. Form ชื่อ frmMain.cs

Smart Device Mobile Application Read and Write Text File

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

namespace SmartDevice
{
    public partial class frmMain : Form
    {
        public frmMain()
        {
            InitializeComponent();
        }

        private void btnWrite_Click(object sender, EventArgs e)
        {
            frmWrite frm = new frmWrite();
            frm.ShowDialog();
        }

        private void btnRead_Click(object sender, EventArgs e)
        {
            frmRead frm = new frmRead();
            frm.ShowDialog();
        }
    }
}









2. Form ชื่อ frmWrite.cs

Smart Device Mobile Application Read and Write Text File

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

namespace SmartDevice
{
    public partial class frmWrite : Form
    {
        public frmWrite()
        {
            InitializeComponent();
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void txtWrite_Click(object sender, EventArgs e)
        {
            if (this.txtInput.Text.Trim() == "")
            {
                MessageBox.Show("Please input Text", "Input Text", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1);
            }
            else
            {
                //*** Create ThaiCreate ***//
                DirectoryInfo DirTc = new DirectoryInfo("\\ThaiCreate");
                if (!DirTc.Exists)
                {
                    DirTc.Create();
                }
                DirTc = null;

                //*** Write to Text file ***/
                string strPath = "\\ThaiCreate\\win.txt";
                StreamWriter StrWer = default(StreamWriter);
                StrWer = new StreamWriter(strPath, true);
                StrWer.WriteLine(this.txtInput.Text);
                StrWer.Close();

                this.txtInput.Text = "";
                MessageBox.Show("Write Text Successful", "Write Text", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);

            }
        }
    }
}


2. Form ชื่อ frmRead.cs

Smart Device Mobile Application Read and Write Text File

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

namespace SmartDevice
{
    public partial class frmRead : Form
    {
        public frmRead()
        {
            InitializeComponent();

            string strPath = "\\ThaiCreate\\win.txt";
            StreamReader StrRer;
            string strLine;
            StrRer = File.OpenText(strPath);

            while (!(StrRer.EndOfStream))
            {
                strLine = StrRer.ReadLine().ToString();
                this.txtShow.Text += strLine + "\r\n";
            }

            StrRer.Close();
          }

        private void btnClose_Click(object sender, EventArgs e)
        {
              this.Close();
        }

    }
}





ทดสอบการรันโปรแกรม

Smart Device Mobile Application Read and Write Text File

เลือก Pocket PC 2003 SE Emulator

Smart Device Mobile Application Read and Write Text File

หน้าจอหลัก

Smart Device Mobile Application Read and Write Text File

สำหรับรับข้อมูลและเขียนลงใน Text File

Smart Device Mobile Application Read and Write Text File

สำหรับนำข้อมูลจาก Text File มาแสดง

Smart Device Mobile Application Read and Write Text File

หลังจากโปรแกรมเสร็จสิ้นแล้ว เมื่อกลับไปยัง Emulator ก็จะพบโฟเดอร์ และไฟล์ที่โปรแกรมได้สร้างไว้

Smart Device Mobile Application Read and Write Text File

ไฟล์ที่ถูกสร้าง

Smart Device Mobile Application Read and Write Text File

รายละเอียดการจัดเก็บไฟล์




เพิ่มเติมสำหรับ Code ภาษา VB.NET

frmMain.vb
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms

Namespace SmartDevice
	Public Partial Class frmMain
		Inherits Form
		Public Sub New()
			InitializeComponent()
		End Sub

		Private Sub btnWrite_Click(sender As Object, e As EventArgs)
			Dim frm As New frmWrite()
			frm.ShowDialog()
		End Sub

		Private Sub btnRead_Click(sender As Object, e As EventArgs)
			Dim frm As New frmRead()
			frm.ShowDialog()
		End Sub
	End Class
End Namespace


frmWrite.vb
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms
Imports System.IO

Namespace SmartDevice
	Public Partial Class frmWrite
		Inherits Form
		Public Sub New()
			InitializeComponent()
		End Sub

		Private Sub btnClose_Click(sender As Object, e As EventArgs)
			Me.Close()
		End Sub

		Private Sub txtWrite_Click(sender As Object, e As EventArgs)
			If Me.txtInput.Text.Trim() = "" Then
				MessageBox.Show("Please input Text", "Input Text", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1)
			Else
				'*** Create ThaiCreate ***//
				Dim DirTc As New DirectoryInfo("\ThaiCreate")
				If Not DirTc.Exists Then
					DirTc.Create()
				End If
				DirTc = Nothing

				'*** Write to Text file ***/
				Dim strPath As String = "\ThaiCreate\win.txt"
				Dim StrWer As StreamWriter = Nothing
				StrWer = New StreamWriter(strPath, True)
				StrWer.WriteLine(Me.txtInput.Text)
				StrWer.Close()

				Me.txtInput.Text = ""

				MessageBox.Show("Write Text Successful", "Write Text", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1)
			End If
		End Sub
	End Class
End Namespace


frmRead.vb
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms
Imports System.IO

Namespace SmartDevice
	Public Partial Class frmRead
		Inherits Form
		Public Sub New()
			InitializeComponent()

			Dim strPath As String = "\ThaiCreate\win.txt"
			Dim StrRer As StreamReader
			Dim strLine As String
			StrRer = File.OpenText(strPath)

			While Not (StrRer.EndOfStream)
				strLine = StrRer.ReadLine().ToString()
				Me.txtShow.Text += strLine & vbCr & vbLf
			End While

			StrRer.Close()
		End Sub

		Private Sub btnClose_Click(sender As Object, e As EventArgs)
			Me.Close()
		End Sub

	End Class
End Namespace









บทความที่เกี่ยวข้อง
Go to : .NET Smart Device เขียนโปรแกรมบน Smartphone, Pocket PC , Windows CE , Window Mobile 5-6
Go to : Shared Folder or Map Drive in Emulator Smart Device Mobile Application


       
Bookmark.   
       

 

  By : TC Admin
  Score Rating : -
  Create Date : 2011-07-30 00:38:25
  Download : Download  Smart Device Mobile Application Read and Write Text File (0.43 MB)
     

Clound SSD Virtual Server
-->
Related Links
.NET Smart Device  เขียนโปรแกรมบน Smartphone, Pocket PC , Windows CE , Window  Mobile 5-6, Hand Held,...
.NET Smart Device เขียนโปรแกรมบน Smartphone, Pocket PC , Windows CE , Window Mobile 5-6, Hand Held,...
.NET Smart Device Project เขียนโปรแกรมบน Smartphone, Pocket PC , Windows CE , Window Mobile 5-6, Hand Held,...
Rating :
Update :
2017-03-24 21:17:48 View : 41,417
VB.NET/C# MySQL (ADO.NET) พื้นฐานการ เขียนโปรแกรม ADO.NET เชื่อมต่อกับฐานข้อมูล MySQL
VB.NET/C# MySQL (ADO.NET) พื้นฐานการ เขียนโปรแกรม ADO.NET เชื่อมต่อกับฐานข้อมูล MySQL
บทความใช้ ADO.NET เชื่อมต่อกับฐานข้อมูล MySQL แบบง่าย ๆ มีตัวอย่างทั้ง VB.NET และ C#
Rating :
Update :
2017-03-24 21:27:18 View : 64,224
VB.NET/C# Create JSON (DataContractJsonSerializer) Serialize and Deserialize
VB.NET/C# Create JSON (DataContractJsonSerializer) Serialize and Deserialize
มาใช้ DataContractJsonSerializer ในการสร้างไฟล์ JSON และ อ่านค่า JSON (Serialize and Deserialize) กันดีกว่า
Rating :
Update :
2017-03-17 21:27:34 View : 20,963
Generating Word Document in .NET Framework
Generating Word Document in .NET Framework
สร้างไฟล์เอกสาร Word Document บน Windows Application และ Console Application ด้วย Framework
Rating :
Update :
2017-03-24 21:20:55 View : 6,537
C# (.Net) Open Excel Template and Create Font,Border,Color,Style (Office 2003,2007,2010)
C# (.Net) Open Excel Template and Create Font,Border,Color,Style (Office 2003,2007,2010)
ตัวอย่างการใช้ C# ในการเปิดไฟล์ Excel ที่มีอยู่ และทำการสร้างเป็น Excel ชุดใหม่ โดยตกแต่งข้อความ เช่น สี , ขนาด ของ ฟอนต์
Rating :
Update :
2017-03-24 21:24:23 View : 21,916
ASP.NET GridView and Checkbox Select All Row Using jQuery
ASP.NET GridView and Checkbox Select All Row Using jQuery
บทความ ASP.NET การใช้งาน jQuery เพื่อเลือกแถว Checkbox ใน GridView เลือกแถวทั้งหมด หรือไม่เลือกทั้งหมด
Rating :
Update :
2017-03-17 22:11:54 View : 16,916
ThaiCreate.Com Forum


Comunity Forum Free Web Script
Jobs Freelance Free Uploads
Free Web Hosting Free Tools

สอน PHP ผ่าน Youtube ฟรี
สอน Android การเขียนโปรแกรม Android
สอน Windows Phone การเขียนโปรแกรม Windows Phone 7 และ 8
สอน iOS การเขียนโปรแกรม iPhone, iPad
สอน Java การเขียนโปรแกรม ภาษา Java
สอน Java GUI การเขียนโปรแกรม ภาษา Java GUI
สอน JSP การเขียนโปรแกรม ภาษา Java
สอน jQuery การเขียนโปรแกรม ภาษา jQuery
สอน .Net การเขียนโปรแกรม ภาษา .Net
Free Tutorial
สอน Google Maps Api
สอน Windows Service
สอน Entity Framework
สอน Android
สอน Java เขียน Java
Java GUI Swing
สอน JSP (Web App)
iOS (iPhone,iPad)
Windows Phone
Windows Azure
Windows Store
Laravel Framework
Yii PHP Framework
สอน jQuery
สอน jQuery กับ Ajax
สอน PHP OOP (Vdo)
Ajax Tutorials
SQL Tutorials
สอน SQL (Part 2)
JavaScript Tutorial
Javascript Tips
VBScript Tutorial
VBScript Validation
Microsoft Access
MySQL Tutorials
-- Stored Procedure
MariaDB Database
SQL Server Tutorial
SQL Server 2005
SQL Server 2008
SQL Server 2012
-- Stored Procedure
Oracle Database
-- Stored Procedure
SVN (Subversion)
แนวทางการทำ SEO
ปรับแต่งเว็บให้โหลดเร็ว


Hit Link
   







Load balance : Server 01
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่

Inline