Subscribe For Free Updates!

We'll not spam mate! We promise.

Jul 29, 2012

Access XML File Hosted on Php Server In Windows Phone 7

Views:

Access XML File Hosted on Php Server In Windows Phone 7
To Day I show you how to Access XML File Hosted on Php web Server Server or any other Server  In Windows Phone 7.

As we Know that Use XML Files For Storing data and Retrieving Data Through LINQ (Language Integrated Query  ).

We can Access an XML file From a Local (Isolated Storage  ) and also From a web server Where XML file Is Hosted .


Note In XML File We Can Store XML file on PHP Server or on Free web Hosting Server.
Following Are the Steps Please Follow it.
First We Create an account on  http://www.000webhost.com/  .It Provides Free PHP web Hosting .Note during Signup Choose SUB Domain which is free and (recommended).
Access XML File Hosted on Php Server In Windows Phone 7

Then Confirm Then Confirmation Email.

Now After Confirmation an Window open in which Select Domain Name From Drop Down and Press Go Buttton By this You Move To Control Penal of You Hosting Account.
Access XML File Hosted on Php Server In Windows Phone 7


Now Select File Manager  (Clcik File Manager ) It ask for Password Enter the Password Which you Write in Signup time.
Access XML File Hosted on Php Server In Windows Phone 7

After this you are now in FTP manager Click Public Folder .Now you have to upload an XML file here i don't have any XML you can download Here Which I uploaded on Server .
my XML file Contains Following Data

<?xml version="1.0" ?>
 <People>
  <Person FirstName="Mohammad Sajjad Ashraf" LastName="AWAN" Age="27" />
  <Person FirstName="Mohammad Javed" LastName="Ashraf" Age="27" />
  <Person FirstName="Mohammad Zain Farooq" LastName="Ansari" Age="27" />
  <Person FirstName="Mohammad Irfan" LastName="Khan" Age="26" />
  <Person FirstName="Mohammad Jibran Ahmed" LastName="Khan" Age="28" />
  <Person FirstName="Kate" LastName="Smith" Age="27" />
  <Person FirstName="Tom" LastName="Brown" Age="30" />
  <Person FirstName="Tim" LastName="Stone" Age="36" />
<Person FirstName="Ann" LastName="Peterson" Age="27" /> 
</People>
Now you Xml File is Live and Sucesfully Hosted.
for viewing  URL of hosted XML file Click (Open Link) it open XML file in new Windows with Complete URL Please Save this URL It needs you in further Steps .
Access XML File Hosted on Php Server In Windows Phone 7
Access XML File Hosted on Php Server In Windows Phone 7
Access XML File Hosted on Php Server In Windows Phone 7

So open Visual Studio and Make a Simple  Project on Windows phone 7 on C#.
you Need a list box with A data Template .List box has Following Code .
<ListBox x:Name="listBox2">
     <ListBox.ItemTemplate>
         <DataTemplate>
              <StackPanel Margin="20" >
                       <TextBlock Text="{Binding FirstName}"/>
                       <TextBlock Text="{Binding LastName}"/>
              </StackPanel>
           </DataTemplate>
        </ListBox.ItemTemplate>
 </ListBox>



Now Add a Class in Project Name Person and Write Following Code

public class Person
    {
        string firstname; string lastname;
        int age;
        public string FirstName
        {
            get { return firstname; }
            set { firstname = value; }
        }
        public string LastName
        {
            get { return lastname; }
            set { lastname = value; }
        }
        public int Age
        {
            get
            {
                return age;
            }
            set
            { age = value; }
        }
    }
And Here The Method Which Loads XML Data From PHP server.
public void loadXmlFromPHpServer(string xmlUrl, ListBox listbox)
   {
   try
   {
   WebClient client = new WebClient();
   client.OpenReadCompleted += (sender, e) =>
   {
   if (e.Error != null)
   return;
   Stream str = e.Result;
   XDocument xdoc = XDocument.Load(str);
   var filteredData = from c in xdoc.Descendants("Person")
   where c.Attribute("Age").Value == "27"
   select new Person()
   {
   FirstName = c.Attribute("FirstName").Value,
   LastName = c.Attribute("LastName").Value
   };
   listbox.ItemsSource = filteredData;
   textBlock1.Text = "Total Items are Loaded =" + filteredData.Count<Person>();
   };
   client.OpenReadAsync(new Uri(xmlUrl, UriKind.Absolute));
   }
   catch (Exception)
   {

   }
   }
You can Call This Method By Using Following Code on PageLoadEvent or Clcik event of Button Etc.
 loadXmlFromPHpServer("http://muhammadsajjadashrafawan.comyr.com/MohammadSajjadAshrafAwan.xml", listBox2);
BENEFITS
1) In this  you can Update Data at Any time
2)It Free Data Server just Only For Data Not For Processing and Computation.
3)Data Is update By Admin .
4)We can Update aur Add more Data in XML File After Your Has been Published in Market Place and It Effects deploy  on  all user who Uses Your App.



DOWNLOAD COMPLETE SOURCE CODE

SCREEN SHORTS
Access XML File Hosted on Php Server In Windows Phone 7


Plese Feel Free to Socializer This Post
SOCIALIZE IT →
FOLLOW US →
SHARE IT →

6 comments:

  1. well done man..i was looking for this one. You made my day :)

    ReplyDelete
  2. The source code file is missing from 4shared, please fix it. Need the source codes!!!

    ReplyDelete
  3. Download From Google Docs Its Working .. https://docs.google.com/file/d/0B0_Q3XaXeFp4ejEwWWl6RkJ2ckk/edit?usp=sharing

    ReplyDelete
  4. Bluehost is definitely one of the best hosting provider with plans for any hosting requirments.

    ReplyDelete
  5. Quantum Binary Signals

    Professional trading signals delivered to your cell phone every day.

    Follow our signals NOW and profit up to 270% daily.

    ReplyDelete
  6. If you want your ex-girlfriend or ex-boyfriend to come crawling back to you on their knees (even if they're dating somebody else now) you gotta watch this video
    right away...

    (VIDEO) Get your ex back with TEXT messages?

    ReplyDelete

Become a Fan

visual studio learn