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 Delete / Remove File In Isolated Storage (Application Storage)



Clound SSD Virtual Server

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

Windows Phone Delete / Remove File In Isolated Storage (Application Storage) การเขียน App บน Windows Phone เพื่อเข้าไปลบ Delete หรือ Remove ไฟล์ต่าง ๆ ที่ถูกจัดเก็บไว้ใน Isolated Storage ของแต่ล่ะ Application โดยในขั้นแรกเราจะแสดงรายชื่อไฟล์ทั้งหมด และให้ผู้ใช้คลิกที่ไฟล์นั้น ๆ เพื่อลบ โดยก่อนที่จะลบจะมีการถาม Confirm เพื่อยืนยันการลบไฟล์ออกจาก Isolated Storage

Windows Phone Delete / Remove File  In Isolated Storage

Windows Phone Delete / Remove File In Isolated Storage


Basic Windows Phone and Isolated Storage (Application Storage)

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

Windows Phone Delete / Remove File  In Isolated Storage

รายชื่อไฟล์ที่อยู่ใน Isolated Storage ของ Application บน Windows Phone

Example ตัวอย่างการลบไฟล์ที่อยู่ใน Isolated Storage แบบง่าย ๆ

MainPage.xaml

Windows Phone Delete / Remove 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-->
    <StackPanel x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
    
    </StackPanel>
        
    </Grid>









MainPage.xaml.vb (VB.NET)
Imports System.IO
Imports System.Text
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)
        ShowAllFile()
    End Sub

    Private Sub ShowAllFile()
        Dim fileList As New List(Of String)

        '*** Ger all file from  Isolated Storage***'
        Dim isoStore As IsolatedStorageFile = IsolatedStorageFile.GetUserStoreForApplication() ' Path Storage
        Dim files As String() = isoStore.GetFileNames("*")
        For Each dirfile As String In files
            fileList.Add(dirfile)
        Next

        '*** Show All Files ***'
        ContentPanel.Children.Clear()
        For Each file As String In fileList
            Dim ctrlHpl As New HyperlinkButton
            ctrlHpl.Content = file.ToString()
            AddHandler ctrlHpl.Click, AddressOf Me.ClickDelete
            ContentPanel.Children.Add(ctrlHpl)
        Next
    End Sub

    Private Sub ClickDelete(ByVal sender As Object, ByVal e As RoutedEventArgs)

        Dim hplItem As HyperlinkButton = DirectCast(e.OriginalSource, HyperlinkButton)
        Dim isoStore As IsolatedStorageFile = IsolatedStorageFile.GetUserStoreForApplication() ' Path Storage

        If MessageBox.Show("Are you sure?", "Delete " & hplItem.Content.ToString, MessageBoxButton.OKCancel) = MessageBoxResult.OK Then
            If isoStore.FileExists(hplItem.Content.ToString) Then
                isoStore.DeleteFile(hplItem.Content.ToString)
            End If
            MessageBox.Show("Delete Completed.", "Result", MessageBoxButton.OK)
            ShowAllFile()
        End If


    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)
        {
            ShowAllFile();
        }

        private void ShowAllFile()
        {
            List<string> fileList = new List<string>();

            //*** Ger all file from  Isolated Storage***'
            IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication();
            // Path Storage
            string[] files = isoStore.GetFileNames("*");
            foreach (string dirfile in files)
            {
                fileList.Add(dirfile);
            }

            //*** Show All Files ***'
            ContentPanel.Children.Clear();
            foreach (string file in fileList)
            {
                HyperlinkButton ctrlHpl = new HyperlinkButton();
                ctrlHpl.Content = file.ToString();
                ctrlHpl.Click += this.ClickDelete;
                ContentPanel.Children.Add(ctrlHpl);
            }
        }


        private void ClickDelete(object sender, RoutedEventArgs e)
        {
            HyperlinkButton hplItem = (HyperlinkButton)e.OriginalSource;
            IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication();
            // Path Storage

            if (MessageBox.Show("Are you sure?", "Delete " + hplItem.Content.ToString(), MessageBoxButton.OKCancel) == MessageBoxResult.OK)
            {
                if (isoStore.FileExists(hplItem.Content.ToString()))
                {
                    isoStore.DeleteFile(hplItem.Content.ToString());
                }
                MessageBox.Show("Delete Completed.", "Result", MessageBoxButton.OK);
                ShowAllFile();
            }


        }


    }

}

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








Screenshot

Windows Phone Delete / Remove File  In Isolated Storage

แสดงรายชื่อไฟล์ที่อยู่ใน Isolated Storage

Windows Phone Delete / Remove File  In Isolated Storage

คลิกที่ไฟลฺเพื่อลบไฟล์ โดยจะมีการถาม Confirm การลบ Delete ไฟล์นั้น ๆ

Windows Phone Delete / Remove File  In Isolated Storage

แสดง Result ว่าไฟล์ถูกลบออกไปแล้ว

Windows Phone Delete / Remove File  In Isolated Storage

ไฟล์ถูกลบออกจากรายการ และไม่แสดงในหน้า Page

Windows Phone Delete / Remove File  In Isolated Storage

เมื่อดูรายการไฟล์ใน Isolated Storage ก็จะถูกลบออกไปเรียบร้อย


.

   
Share


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


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


   


Bookmark.   
       
  By : ThaiCreate.Com Team (บทความเป็นลิขสิทธิ์ของเว็บไทยครีเอทห้ามนำเผยแพร่ ณ เว็บไซต์อื่น ๆ)
  Score Rating :  
  Create/Update Date : 2012-09-15 11:13:20 / 2017-03-25 22:20:43
  Download : Download  Windows Phone Delete / Remove 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 Read Text 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 05
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 อัตราราคา คลิกที่นี่