locked
How to RetrieveFeedAsync by a file ?

    Question

  • Hi..

     I want to build a syndication client and a syndication feed and retrieve feed asynchronously by a file.. Not a URI...

    and here is the code Ive tried..

    NOTE: The rss feed I want to get is in a file App's local folder and I has been created by the same program.

    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(@"http://lankadeepa.lk/index.php/maincontroller/breakingnews_rss");
                request.Method = "GET";
                var response = await request.GetResponseAsync();
                string data = string.Empty;
                using (StreamReader reader = new StreamReader(response.GetResponseStream()))
                    data = await reader.ReadToEndAsync();
                textBox1.Text = data.ToString();
                textBox1.Text = textBox1.Text.Replace(@"</admin:generatoragent>", @"</admin:generatorAgent>");
    
                StorageFile file = await ApplicationData.Current.LocalFolder.CreateFileAsync("xmlcodes.txt", CreationCollisionOption.ReplaceExisting);
                await FileIO.WriteTextAsync(file, textBox1.Text);
    
                
    
                string feedpath =  file.Path.ToString();
    
                
    
                SyndicationClient client = new SyndicationClient();
                SyndicationFeed feed = await client.RetrieveFeedAsync(new Uri(feedpath));
    
                textBox1.Text = "";
    
                foreach (SyndicationItem item in feed.Items)
                {
                    textBox1.Text += item.Title.ToString() + Environment.NewLine + item.Summary.Text.ToString() +
                        Environment.NewLine + Environment.NewLine;
                }


    StorageFile file contains the feed..

    This code shows an error  Here is the error..

    **************************************************************************************************

    An exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll but was not handled in user code

    Additional information: The filename, directory name, or volume label syntax is incorrect. (Exception from HRESULT: 0x8007007B)

    **************************************************************************************************

    What's the wrong with my code ??

    And please dont tell me retrieve the feed from the uri directly what I have used to create a web request.. It's not pissible..  Because in the rss feed there is a error in the XML code.. Therefore SyndicationClient stop workingif I use that URI.. 

    All I want to know is how to retreive feed from a file inside the computer properly ?

    Thanks.

    Monday, February 10, 2014 9:02 AM

Answers

All replies

  • Hi StringAstro,

    It seems like there is something wrong with StorageFile instance. This thread is related to Windows Store App. I will help you moving this thread into Store App forum for effective response. Thank you for understanding.

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, February 11, 2014 3:04 AM
    Moderator
  • Try flushing and closing the file before passing it to RetrieveFeedAsync. Look at the value of feedpath in the debugger and make sure the file exists and contains the data you expect.
    Tuesday, February 11, 2014 3:52 AM
    Owner
  • What ? :O Is there another forum for Winrt App developers ? :O  I should have known about that..  Gimme the link please :D
    Tuesday, February 11, 2014 7:12 AM
  • What do you mean by flushing and closing file ?? o_O How on earth would I flush and close a file ?? o_O

    Anyway there is no error with the file path.. I checked it.. The file does exist in the location..

    • Edited by string Astro Tuesday, February 11, 2014 7:15 AM Added few more information
    Tuesday, February 11, 2014 7:14 AM
  • Hetro already moved this to the Building Windows Store apps with C# or VB forum for you.

    --Rob

    Tuesday, February 11, 2014 7:15 AM
    Owner
  • OK Thanks..
    Tuesday, February 11, 2014 7:17 AM
  • Open the debugger and set a breakpoint on the line of code where you assign Feedpath.

    What is the value of feedpath? 


    Jeff Sanders (MSFT)

    @jsandersrocks - Windows Store Developer Solutions @WSDevSol
    Getting Started With Windows Azure Mobile Services development? Click here
    Getting Started With Windows Phone or Store app development? Click here
    My Team Blog: Windows Store & Phone Developer Solutions
    My Blog: Http Client Protocol Issues (and other fun stuff I support)

    Friday, February 14, 2014 3:13 PM
    Moderator
  • feedpath value is "C:\Users\Astro\AppData\Local\Packages\4f3f759f-8612-4a87-8a71-d139cafbb8a0_xfk21‌​ev7ernpw\LocalState\xmlcodes.txt"

    and what do you mean by "Open the debugger and set a breakpoint on the line of code"

    Saturday, February 15, 2014 6:44 AM
  • That file path is invalid.  You cannot access the file system directly.  Here is a sample on using local storage:

    http://msdn.microsoft.com/en-us/library/windows/apps/windows.storage.applicationdata.localfolder.aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-2

    You want to access files in the local folder through .GetFileAsync on the LocalFolder object and you will be fine!

    Jeff


    Jeff Sanders (MSFT)

    @jsandersrocks - Windows Store Developer Solutions @WSDevSol
    Getting Started With Windows Azure Mobile Services development? Click here
    Getting Started With Windows Phone or Store app development? Click here
    My Team Blog: Windows Store & Phone Developer Solutions
    My Blog: Http Client Protocol Issues (and other fun stuff I support)

    Monday, February 17, 2014 3:37 PM
    Moderator
  • And here is the code I tried following your answer..

    //string feedpath = file.Path.ToString();
                //textBox1.Text = feedpath;
    
                StorageFile feedfile = await ApplicationData.Current.LocalFolder.GetFileAsync("feed.xml");
                
                
    
                SyndicationClient client = new SyndicationClient();
                SyndicationFeed feed = await client.RetrieveFeedAsync(new Uri(feedfile.Path));//error
    

    But it doesnt working either... And here is the error I got...

    ****************************************************************************************

    An exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll but was not handled in user code

    Additional information: The filename, directory name, or volume label syntax is incorrect. (Exception from HRESULT: 0x8007007B)

    ****************************************************************************************

    Anyway in the question I tried it with the localfolder though.. So there couldnt be any error with the accessing the file.. The problem must be in the URI..

    Tuesday, February 18, 2014 4:44 AM
  • And I tried this code too...

    //Retrieving text
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(@"http://lankadeepa.lk/index.php/maincontroller/breakingnews_rss");
                request.Method = "GET";
                var response = await request.GetResponseAsync();
                string data = string.Empty;
                using (StreamReader reader = new StreamReader(response.GetResponseStream()))
                    data = await reader.ReadToEndAsync();
    
                data = data.Replace("<admin:generatorAgent rdf:resource=\"http://www.codeigniter.com/\" />", string.Empty);
                data = data.Replace("</admin:generatoragent>", string.Empty);
    
                StorageFile file = await ApplicationData.Current.LocalFolder.CreateFileAsync("feed.xml", CreationCollisionOption.ReplaceExisting);
                await FileIO.WriteTextAsync(file, data);
    
                //string feedpath = file.Path.ToString();
                //textBox1.Text = feedpath;
    
                StorageFile feedfile = await ApplicationData.Current.LocalFolder.GetFileAsync("feed.xml");
    
                var url = new Uri(feedfile.Path);
                string converted = url.AbsoluteUri;
    
                SyndicationClient client = new SyndicationClient();
                SyndicationFeed feed = await client.RetrieveFeedAsync(new Uri(converted));//error

    It doesnt work either..

    Tuesday, February 18, 2014 4:48 AM
  • Hi Astro,

    Ah...

    You want to load the feed not do a RetriveFeedAsync:

    http://social.msdn.microsoft.com/Forums/windowsapps/en-US/d0418116-210b-4483-b6f3-0b62c129ab06/loading-xml-from-memory-in-winrt?forum=winappswithcsharp


    Jeff Sanders (MSFT)

    @jsandersrocks - Windows Store Developer Solutions @WSDevSol
    Getting Started With Windows Azure Mobile Services development? Click here
    Getting Started With Windows Phone or Store app development? Click here
    My Team Blog: Windows Store & Phone Developer Solutions
    My Blog: Http Client Protocol Issues (and other fun stuff I support)

    Wednesday, February 19, 2014 7:48 PM
    Moderator
  • SyndicationFeed myfeed = new SyndicationFeed();
                myfeed.LoadFromXml(file);

    it cannot be loaded :( It says 

    ******************

    Error 1 The best overloaded method match for 'Windows.Web.Syndication.SyndicationFeed.LoadFromXml(Windows.Data.Xml.Dom.XmlDocument)' has some invalid arguments C:\Users\Astro\documents\visual studio 2013\Projects\Lankadeepa App (Testing)\Lankadeepa App (Testing)\MainPage.xaml.cs 168 13 Lankadeepa App (Testing)

    ********************

    Thursday, February 20, 2014 3:35 PM
  • I will help you help yourself!  What does the documentation for that API say it takes?  How can you give that to the API?

    Jeff Sanders (MSFT)

    @jsandersrocks - Windows Store Developer Solutions @WSDevSol
    Getting Started With Windows Azure Mobile Services development? Click here
    Getting Started With Windows Phone or Store app development? Click here
    My Team Blog: Windows Store & Phone Developer Solutions
    My Blog: Http Client Protocol Issues (and other fun stuff I support)

    Thursday, February 20, 2014 3:44 PM
    Moderator