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 > Mobile > Windows Phone Dev - สอนเขียน App บนโปรแกรม Windows Phone 7 , Windows Phone 8 > Windows Phone Read Text File in Isolated Storage (Application Storage)



Clound SSD Virtual Server

Windows Phone Read Text File in Isolated Storage (Application Storage)

Windows Phone Read Text File in Isolated Storage (Application Storage) ตัวอย่างการเขียน App บน Windows Phone เพื่ออ่าน Text file (Read Text file) ที่ถูกจัดเก็บไว้ใน Isolated Storage ของ Application บน Windows Phone และนำข้อความที่ได้จาการอ่านมาแสดงในหน้า Page ของ Application โดยใช้การ Binding Data ลงใน Controls ของ ListBox

Windows Phone Read Text File in Isolated Storage

Windows Phone Read Text File in Isolated Storage


Basic Windows Phone and Isolated Storage (Application Storage)

สำหรับพื้นฐาน Isolated Storage กับ Windows Phone ควรอ่าน 2 บทความนี้ เพื่อความเข้าใจ

Windows Phone Read Text File in Isolated Storage

ไฟล์ thaicreate.txt ที่ถูกจัดเก็บไว้ใน Isolated Storage

Example ตัวอย่างการอ่าน Text file ที่อยู่ใน Isolated Storage

MainPage.xaml

Windows Phone Read Text File in Isolated Storage

    <!--LayoutRoot is the root grid where all page content is placed-->
    <Grid x:Name="LayoutRoot" Background="Transparent">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <!--TitlePanel contains the name of the application and page title-->
        <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
            <TextBlock x:Name="ApplicationTitle" Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}"/>
            <TextBlock x:Name="PageTitle" Text="page name" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
        </StackPanel>

        <!--ContentPanel - place additional content here-->
        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
            <ListBox Margin="0,0,-12,0" x:Name="myList">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Width="311">
                            <TextBlock Text="{Binding Msg}"  TextWrapping="Wrap" Style="{StaticResource PhoneTextSubtleStyle}"/>
                        </StackPanel>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
        </Grid>

    </Grid>









MainPage.xaml.vb (VB.NET)
Imports System.IO
Imports System.IO.IsolatedStorage

Partial Public Class MainPage
    Inherits PhoneApplicationPage

    ' Constructor
    Public Sub New()
        InitializeComponent()

        AddHandler Loaded, AddressOf MainPage_Loaded
    End Sub

    Private Sub MainPage_Loaded(sender As Object, e As System.Windows.RoutedEventArgs)
        Dim isoStore As IsolatedStorageFile = IsolatedStorageFile.GetUserStoreForApplication()
        Dim strFileName As String = "thaicreate.txt"

        Dim reader As StreamReader = New StreamReader(New IsolatedStorageFileStream(strFileName, FileMode.Open, isoStore))
        Dim rawData As String = reader.ReadToEnd()
        reader.Close()

        Dim sep As String() = New String() {vbCr}
        Dim arrData As String() = rawData.Split(sep, StringSplitOptions.RemoveEmptyEntries)

        Dim myContact As New List(Of Message)
        For Each strLine In arrData
            myContact.Add(New Message(strLine.ToString()))
        Next

        Me.myList.ItemsSource = myContact

    End Sub

End Class


Public Class Message

    Public Property Msg() As String
        Get
            Return m_Msg
        End Get
        Set(value As String)
            m_Msg = value
        End Set
    End Property

    Private m_Msg As String

    Public Sub New(ByVal strMsg As String)
        Me.Msg = strMsg
    End Sub

End Class

MainPage.xaml.cs (C#)
using System;
using System.Windows;
using System.Net;
using System.IO;
using System.Text;
using System.IO.IsolatedStorage;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using System.Collections.Generic;
using System.Windows.Controls;

namespace PhoneApp
{
    public partial class MainPage : PhoneApplicationPage
    {

        // Constructor
        public MainPage()
        {
            InitializeComponent();

            Loaded += MainPage_Loaded;
        }

        private void MainPage_Loaded(object sender, System.Windows.RoutedEventArgs e)
	    {
		    IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication();
		    string strFileName = "thaicreate.txt";

		    StreamReader reader = new StreamReader(new IsolatedStorageFileStream(strFileName, FileMode.Open, isoStore));
		    string rawData = reader.ReadToEnd();
		    reader.Close();

		    string[] sep = new string[] { "\r\n" };
		    string[] arrData = rawData.Split(sep, StringSplitOptions.RemoveEmptyEntries);

		    List<Message> myContact = new List<Message>();
		    foreach (var strLine in arrData) {
			    myContact.Add(new Message(strLine.ToString()));
		    }

		    this.myList.ItemsSource = myContact;

        }
    }

    public class Message
    {

        public string Msg
        {
            get { return m_Msg; }
            set { m_Msg = value; }
        }

        private string m_Msg;
        public Message(string strMsg)
        {
            this.Msg = strMsg;
        }

    }
}

ในตัวอย่างนี้มี Code ทั้งที่เป็น VB.NET และ C# และสามารถดาวน์โหลด All Code ทั้งหมดได้จากส่วนท้ายของบทความ (Login สมาชิกก่อน)








Screenshot

Windows Phone Read Text File in Isolated Storage

แสดงข้อความที่อยู่ใน Text file และถูก Binding แสดงบน ListBox

   
Share


ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท


ลองใช้ค้นหาข้อมูล


   


Bookmark.   
       
  By : ThaiCreate.Com Team (บทความเป็นลิขสิทธิ์ของเว็บไทยครีเอทห้ามนำเผยแพร่ ณ เว็บไซต์อื่น ๆ)
  Score Rating :  
  Create/Update Date : 2012-09-15 11:41:30 / 2017-03-25 22:17:25
  Download : Download  Windows Phone Read Text File in Isolated Storage (Application Storage)
 Sponsored Links / Related

 
Windows Phone and Isolated Storage (Application Storage)
Rating :

 
Windows Phone ListBox Image Binding and Resource from Isolated Storage (Application Storage)
Rating :

 
Windows Phone Play MP3 or Video MediaElement from Isolated Storage (Application Storage)
Rating :

 
Windows Phone Copy Transfer file from PC Between Isolated Storage (Application Storage)
Rating :

 
Windows Phone Download Save file to Isolated Storage (Application Storage)
Rating :

 
Windows Phone Create and Write Text File In Isolated Storage (Application Storage)
Rating :

 
Windows Phone Delete / Remove File In Isolated Storage (Application Storage)
Rating :

 
Windows Phone List Show File In Isolated Storage (Application Storage)
Rating :

 
Windows Phone Image Source From Isolated Storage (Application Storage)
Rating :


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 00
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 อัตราราคา คลิกที่นี่