windows phone 7
  
Welcome, Guest. Please login or register.
Did you miss your activation email?

News: Do you like Windows Phone 7?    
Advanced search
Scratch-Proof your Windows Phone 7                      Best Screen Protector for Windows Phone 7 Cheap Cell Phone Accessories
Pages: [1]
Print
Share this topic on AskShare this topic on Del.icio.usShare this topic on DiggShare this topic on FacebookShare this topic on GoogleShare this topic on LiveShare this topic on MySpaceShare this topic on RedditShare this topic on SlashdotShare this topic on SpurlShare this topic on SquidooShare this topic on StumbleUponShare this topic on TwitterShare this topic on TipdShare this topic on YahooShare this topic on Google buzz
Author Topic: LINQ to XML | Isolated Storage | Visual Basic 2010 | VB | Windows Phone 7 | WP7  (Read 92 times)
ekimov
Newbie
*

Thank You / Karma 0
Offline Offline

United States United States

Posts: 2


WWW
« on: November 24, 2011, 09:55:16 AM »

LINQ to XML | Isolated Storage | Visual Basic 2010 | VB | Windows Phone 7 | WP7

I am developing a wp7 app which basically have to write, read to xml file in Isolated Storage of windows phone 7. First and more important this post is for Visual Basic 2010 NOT for C#. Please, do not paste a C# code and say just translate to visual basic 2010, this does not work. Please, help and post code only if it is Visual Basic 2010 for Windows Phone 7 | WP7.

My questions are:
1. How to create file?
2. How to save it to Isolated Storage?
3. How to Open file?
4. How to write to file and add new rows?
5. How to save(update) the file?
6. How to read the file and make queries from it?

Please, provide your solution. Bellow I am posting the code I have been done and does not work very well  Cry

1. Imports required libraries:

Code:
Imports System
Imports System.IO
Imports System.IO.IsolatedStorage
Imports System.Linq
Imports System.Xml.Linq

Partial Public Class MainPage
    Inherits PhoneApplicationPage
    Dim xmlDoc As XDocument
    Dim xmlFile As IsolatedStorageFileStream
    Dim myStartShift As New DeliveryObj.StartShift
    Dim myEndShift As New DeliveryObj.EndShift
    ' Constructor
    Public Sub New()
        InitializeComponent()
    End Sub

2. Creating 2 classes StartShift and EndShift:
Code:
Class StartShift
    Private dtStartShiftDateTime As DateTime
    Public Property StartShiftDateTime() As DateTime
        Get
            Return dtStartShiftDateTime
        End Get
        Set(value As DateTime)
            dtStartShiftDateTime = value
        End Set
    End Property
    Public Sub StartShift(ByVal StartShiftDateTime As DateTime)
        dtStartShiftDateTime = StartShiftDateTime
    End Sub
End Class
Class EndShift
    Private dtEndShiftDateTime As DateTime
    Public Property EndShiftDateTime() As DateTime
        Get
            Return dtEndShiftDateTime
        End Get
        Set(value As DateTime)
            dtEndShiftDateTime = value
        End Set
    End Property
    Public Sub EndShift(ByVal EndShiftDateTime As DateTime)
        dtEndShiftDateTime = EndShiftDateTime
    End Sub
End Class

3. Connecting to the App Isolated Storage creating xml file and save it:
Code:
Public Sub xmlStorage()
        Dim x As XDocument = _
            <?xml version="1.0" encoding="utf-8" standalone="yes"?>
            <user>
                <startShift></startShift>
                <endShift></endShift>
            </user>
        Using seStorage As IsolatedStorageFile = IsolatedStorageFile.GetUserStoreForApplication()
            If seStorage.FileExists("1d.xml") Then
                Using xmlFile As IsolatedStorageFileStream = seStorage.OpenFile("1d.xml", FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite)
                    xmlDoc = XDocument.Load(xmlFile)
                End Using
            Else
                Using xmlFile As IsolatedStorageFileStream = seStorage.CreateFile("1d.xml")
                    x.Save(xmlFile) ' Here something breaking when saving file, but after restart debugger when file already exists everything works fine.
                End Using
            End If
        End Using

4. Creating Button "Start Shift" = btnStartShift
Code:
Private Sub btnStartShift_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles btnStartShift.Click
        btnStartShift.IsEnabled = False
        btnEndShift.IsEnabled = True
        myStartShift.StartShift(DateTime.Now)
        Call xmlStorage()
        Dim x = New XElement(<startShift><%= myStartShift.StartShiftDateTime %></startShift>)
        xmlDoc.Root.LastNode.AddAfterSelf(x)
        xmlDoc.Save(xmlFile) ' ArgumentNullException was unhandled. ==> Here is breaking
        xmlDoc = XDocument.Load(xmlFile)
        MessageBox.Show(xmlFile.ToString)
        MessageBox.Show(xmlDoc.ToString)
    End Sub

5. Creating Button "End Shift" = btnEndShift
Code:
   Private Sub btnEndShift_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles btnEndShift.Click
        btnStartShift.IsEnabled = True
        btnEndShift.IsEnabled = False
        myEndShift.EndShift(DateTime.Now)
        Call xmlStorage()
        Dim x = New XElement(<endShift><%= myEndShift.EndShiftDateTime %></endShift>)
        xmlDoc.Root.LastNode.AddAfterSelf(x)
        xmlDoc.Save(xmlFile) ' ArgumentNullException was unhandled. ==> Here is breaking
        xmlDoc = XDocument.Load(xmlFile)
        MessageBox.Show(xmlFile.ToString)
        MessageBox.Show(xmlDoc.ToString)
    End Sub

I am attaching the source code in case anyone want to debug it.
Thanks in advance for your cooperation and I will wait for your solution reply's.
Logged

Great Search Engine | AdVader.com
Great Shopping | SeeTheDeal.com
Popular Domain Name | WebFace.com
ekimov
Newbie
*

Thank You / Karma 0
Offline Offline

United States United States

Posts: 2


WWW
« Reply #1 on: November 29, 2011, 02:55:32 PM »

Still no replays. Please, guys give me an idea how to save the xmlFile. Thank you.
Logged
Pages: [1]
Print
Jump to:  






Thanks for visiting Windows Phone 7 Powered by SMF 1.1.12 | SMF © 2006-2009, Simple Machines LLC Sitemap

Galaxy S3 | Galaxy Note | Galaxy Nexus | Kindle Fire | Atrix 4G | Motorola Xoom | Windows Phone 7
Nokia Lumia | Tech Support Forum | Top Hosts | Samsung Galaxy Tab | Samsung Galaxy S2 | Samsung Galaxy S | Samsung Wave
HTC Evo 3D | HTC Evo 4G | HTC Incredible | HTC Incredible 2 | HTC Incredible S | HTC Thunderbolt
Motorola Droid Razr
| HTC Desire | HTC Desire HD | HTC Desire Z | HTC Desire S | HTC Wildfire
Motorola Droid | Galaxy Indulge | Nokia N8 | Droid Charge | Droid X | Droid X2 | Droid 2| Droid 3 | Fascinate
HTC Sensation | HTC Flyer | LG Revolution | Asus Transformer | Xperia Play | iPhone 4 | Nexus S | Droid Bionic
HTC One | HTC Wildfire S | HTC Droid Eris


This is an Un-Official fan based Website. The views expressed on this website are solely those of the proprietor, or contributors to the site, and do not necessarily reflect the views or opinions of the parties it covers, and is not affiliated with, endorsed or sponsored by parties involved.
If you have a problem with any of the content posted on this website, please contact "mobile@vssupportqueue.com"
Term of Use | Privacy Policy | BlackRain 2006 by, Crip