tags:

views:

46

answers:

2

Hi guys, You can call me marcus. I'm currently studying in a polytechnic in singapore and i'm doing my final year project. And my task is to create a application which is able to connect to my own server. Well, before i start off with anything, i did my research and came across a website, Building Your First Windows Phone App with Silverlight and Visual Studio 2010 Submitted by Alvin Ashcraft on Wed, 2010/03/24 - 9:30am. I have copied everything as at the webpage but my final result was that i had some errors and i'm not too sure why is that so. Would it be okay if you guys can tell me where have i gone wrong? Sorry but to trouble you guys. I am new to this programming and would hope to learn something from you guys. For any of your referrence, the webpage is http://dotnet.dzone.com/articles/building-your-first-windows?mz=27249-windowsphone7

This is the code i typed which is exactly the same on the webpage. But there were 3 error. The errors are as below.

The name 'XElement' does not exist in the current context
Mainpage.xaml.cs 49 27 The type of namespace name 'XElement' could not be found ( are you missing a using directive or an assembly reference?)
Mainpage.xaml.cs 49 5 The type of namespace name 'XNamespace' could not be found ( are you missing a using directive or an assembly reference?) Mainpage.xaml.cs 50 5

The code of mine which i copied from the website is below. Really thank you if you could help me with this.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;

namespace DotNetZoneReader
{
    public partial class MainPage : PhoneApplicationPage
    {
        public MainPage()
        {
            InitializeComponent();

            SupportedOrientations = SupportedPageOrientation.Portrait | SupportedPageOrientation.Landscape;
        }

        private void listBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {

        }

        private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
        {

        }

        private void storyList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {

        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            var dzoneRss = new WebClient();
            dzoneRss.DownloadStringCompleted += dzoneRss_DownloadStringCompleted;
            dzoneRss.DownloadStringAsync(new Uri("http://feeds.dzone.com/zones/dotnet"));
        }
        private void dzoneRss_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
    if (e.Error != null) return;
    XElement xmlStories = XElement.Parse(e.Result);
    XNamespace dz = "http://www.developerzone.com/modules/dz/1.0";
    storyList.ItemsSource = from story in xmlStories.Descendants("item")
    select new FeedItem
                           {

Title = story.Element("title").Value,

Description =  story.Element("description").Value,

Link =  story.Element("link").Value,

PublishDate = Convert.ToDateTime(story.Element(dz + "submitDate").Value).ToString("dd-MMM"),

Author = story.Element(dz + "submitter").Element(dz + "username").Value,

AuthorImageUrl = story.Element(dz + "submitter").Element(dz + "userimage").Value

};
}
        public class FeedItem
    {
    public string Title { get; set; }
    public string Description { get; set; }
    public string Link { get; set; }
    public string PublishDate { get; set; }
    public string Author { get; set; }
    public string AuthorImageUrl { get; set; }
}
    }
}

Hope to hear from you soon and really appreciate if you can help me with it please and sorry to trouble you. :) Yours Sincerely, Marcus

+2  A: 

Add this System.Xml.Linq If you don't find this then add reference of this dll in your project first.

using System.Xml.Linq;

OR use it like this but above is better.

System.Xml.Linq.XElement
Muhammad Kashif Nadeem
Hi Muhammad Kashif Nadeer, thanks for your answer. I have also tried your method but a new error occurred. Sorry but this is my first time on this programming. Would it be okay, if you can simply things?
marcus
using System.Xml.Linq; using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; using Microsoft.Phone.Controls;
marcus
I add the using Systeml.Xml.Linq; but still i occured with the error. Sorry for making myself seems so new to all this
marcus
+2  A: 

The problem is pointed out in the comment to that article:

Paul Millsaps replied on Thu, 2010/03/25 - 11:16am

Very nice article. One issue is the System.Linq.Xml above should actually be System.Xml.Linq, I believe. Thanks!

This means you must ensure that your project has a reference to System.Xml.Linq (in the References node in Solution Explorer), and you also must have the line

using System.Xml.Linq;

in the using directives area at the start of the code file.

AakashM
Hi AakashM, Thanks for the answer you have given. I have tried copying the using System.Xml.Xpath; but it doesnt work still. It keeps saying that i'm missing an assembly reference. Sorry for troubling you. And sorry that i'm a novice in this and i still have much more to learn from you guys. Thanks for helping really, but can you probably simplify what you said. I got abit lost, i simply copied in the part and there's a new error. Thanks alot buddy
marcus
@marcus oops there was another typo, it's actually `using System.Xml.Linq;` you'll need in your code (as well as adding the reference)
AakashM
@ AakashM Oh mine it worked. Haha, finally i'm like so relived. But still it's just a try out for myself. The final thing i have to do is to create a application which can be connected to my own server(.aspx). Hope you really could assist me ^^ Anyway you could be as a role model of mine. I mean there are so many pros in this world who are really really good at programming like you. Feel so left out ): I am new to this and my lecturer expects me to create a icon so that when i click on it i have access to my own server page.
marcus
@ AakashM Something like the dictionary app in Iphone. Whereby i key in a word and i'm able to see all the definations. He expects me to create something like this. Omg, AakashM you're mine only saviour ! ): Haha.
marcus