[C#] URI behaving badly

Results 1 to 6 of 6
  1. #1
    Grand Master ryuchao009 is offline
    Grand MasterRank
    Feb 2009 Join Date
    United StatesLocation
    601Posts

    [C#] URI behaving badly

    Hi, I've been trying to work on a patcher for flyff in C# for the past few days due to boredom

    I've been able to use NavigationService() linked to my frame in XAML to do webpage navigation, but when I try to use variables to set up the navigation, I get an exception.

    This is the code for how I have the NavigationService() set up
    PHP Code:
    String NewsPageNavigation "http://" Configuration.IPaddress "/" Configuration.Newspage;
    NewsPage.NavigationService.Navigate(new Uri(NewsPageNavigation)); 
    I had also tried using new Uri() and inputting the contents for the string there, but I kept getting the same exception.

    This is the code for the classes (it seemed the easiest way to make my configuration variables universal throughout the program)
    PHP Code:
     public static string configfile "config.txt";
     public static 
    string UpdateCheckerFile "list.txt.gz";
     public static 
    float UpdaterVersion;
     public static 
    string NeuzParam;
     public static 
    string IPaddress;
     public static 
    string Newspage;
     public static 
    string Registerpage;
     public static 
    string PatchDir;
     public static 
    string ResourcesFolder
    This is how I was reading in the contents of my configuration file
    PHP Code:
    TextReader txtConfig = new StreamReader(Configuration.configfile);
    {
         
    Configuration.UpdaterVersion txtConfig.Read();
         
    txtConfig.ReadLine(); //I added this because I was getting an exception with the Navigation trying to use NeuzParam in the URI string
         
    Configuration.NeuzParam txtConfig.ReadLine();
         
    Configuration.IPaddress txtConfig.ReadLine();
         
    Configuration.Newspage txtConfig.ReadLine();
         
    Configuration.Registerpage txtConfig.ReadLine();
         
    Configuration.PatchDir txtConfig.ReadLine();
         
    Configuration.ResourcesFolder txtConfig.ReadLine();
    }
    txtConfig.Close(); 
    Lastly, Here's the contents of my config.txt
    Code:
    1.0 
    sunkist
    localhost  
    newspage.php
    register.php 
    Neurospace/RESCLIENT 
    Resources
    I'm using VS 2010 Beta 2 so I don't know if that's the problem or not. When I used Uri("http://localhost/newspage.php") it works fine, just not when I try to do it with my configuration variables and the + operator. I set up a try...catch to make sure it's reading in the correct lines for the Uri, and the ouput it's giving says that it is. I can post some screenshots if it'll help.

    If you've got any suggestions, please let me know. I've spent a few hours googling around with no luck.
    Last edited by ryuchao009; 19-12-09 at 05:21 PM. Reason: put the C# code in php tags


  2. #2
    :-) s-p-n is offline
    DeveloperRank
    Jun 2007 Join Date
    Next DoorLocation
    2,097Posts

    Re: [C#] URI behaving badly

    I don't really know C# at all, but I did some searching around.
    PHP Code:
    String NewsPageNavigation "http://" Configuration.IPaddress "/" Configuration.Newspage
    Uri myUri = new Uri(NewsPageNavigation);
    WebRequest wr WebRequest.Create(myUri); 
    Just taking a shot in the dark here, but your syntax doesn't match too well with other references I found. Maybe you can pick apart something and make it work..

    http://msdn.microsoft.com/en-us/library/system.uri.aspx

  3. #3
    Grand Master ryuchao009 is offline
    Grand MasterRank
    Feb 2009 Join Date
    United StatesLocation
    601Posts

    Re: [C#] URI behaving badly

    Thanks for trying, but still no good. I'm getting the same error as the other way I was doing it

    Error:
    Code:
    System.UriFormatException: Invalid URI: The hostname could not be parsed.
     at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)
     at System.Uri..ctor(String uriString)
     at flyff_patcher.MainWindow..ctor() in X:\Useers\Myusername\Documents\Visual Studio 2010\Projects\flyff_patcher\flyff_patcher\MainWindow.xaml.cs:line 38
    I forgot to mention why I was using NavigationService() lol. I coded the interface in XAML, and the guide I was reading about XAML frames said to use NavigationService() to load a webiste inside of the frame.
    Last edited by ryuchao009; 19-12-09 at 09:46 PM.

  4. #4
    :-) s-p-n is offline
    DeveloperRank
    Jun 2007 Join Date
    Next DoorLocation
    2,097Posts

    Re: [C#] URI behaving badly

    Have you tried these?
    http://msdn.microsoft.com/en-us/library/ms591051.aspx
    (example of use)
    Quote Originally Posted by .NET Framework Developer Center
    void goObjectButton_Click(object sender, RoutedEventArgs e)
    {
    this.NavigationService.Navigate(new ContentPage());
    }
    To replace "ContentPage()"..?
    http://msdn.microsoft.com/en-us/libr...rols.page.aspx

  5. #5
    Newbie Ilar is offline
    MemberRank
    Dec 2009 Join Date
    3Posts

    Re: [C#] URI behaving badly

    The following code works ok:
    Code:
                string address = "localhost";
                string file = "news.php";
    
                string fullAddress = "http://" + address + "/" + file;
    
                Uri testURI = new Uri(fullAddress);
    
                Console.WriteLine("Successfully created Uri object for: " + testURI.AbsoluteUri);
                Console.ReadKey();
    are you sure that Configuration.IPaddress is populated with value at the moment when you use it to create address?
    Add it to watchlist and set a breakpoint at that line or add something like Console.WriteLine(Configuration.IPaddress) below or above that line and look what it will produce.

  6. #6
    Grand Master xSilv3rbullet is offline
    Grand MasterRank
    Apr 2009 Join Date
    1,226Posts

    Re: [C#] URI behaving badly

    Why don't you do the following:
    On the website, make a file called latestversion.v.

    In that, type in the latest version (Ex, 5).

    Now, use WebClient to connect to that page and download the content
    (which would be the version you typed in; (Ex. 5))

    Then, get the version of the current client, and if its older, download the new file, by using WebClient to download the content of the EXE and renaming it to an exe.

    Example:
    The latest client is located at web.tld/new.exe

    Use WebClient to download new.exe, then rename the resulting file to client.exe (or whatever)

    You could do something with updating certain parts of the file to make the update faster, but that's advanced stuff.



Advertisement