Error passing parameter to function

Asked

Viewed 89 times

1

I’ve lost full access to my websites and I’m trying to pass the posts from it to a new one. I have a code that reads the sitemap and takes the urls and another who picks up the url, separates the part I need and posted on my new website.

static void Main(string[] args)
{
    var website = XMLReader("SITE");
    Postagem(website.ToString());
    Console.WriteLine("Total de Posts adicionados: " + website.Count());
    Console.ReadLine();
}

By passing my site as a parameter to XMLReader he reads the sitemap and return me the urls all right.

As you pass these urls for the function Postagem, with the Try/Catch, he gives me the error back:

Error: System.Uriformatexception: Invalid URI: The format of the URI could not be determined.

But if I pass :

Postagem("LINK DO POST");

He puts everything right. What would be the mistake? I did not find anything on the net.

private static void Postagem(string website)
{
    try
    {
        string link = "SITE";
        string username = "USER_WP";
        string password = "SENHA_WP";
        HtmlWeb web = new HtmlWeb();
        HtmlDocument resultat = web.Load(website);
        string titulopost = resultat.DocumentNode.SelectNodes("//*[contains(@class,'entry-title')]")[0].InnerHtml;
        string conteudo = resultat.DocumentNode.SelectNodes("//*[contains(@class,'entry-content')]")[0].InnerHtml;
        var wp = new WordPressWrapper(link + "/xmlrpc.php", username, password);
        var post = new Post();
        Console.WriteLine("Adicionando post: " + titulopost);

        post.DateCreated = DateTime.Today.AddHours(0);
        post.Title = titulopost;
        post.Body = conteudo;

        wp.NewPost(post, true);
    }
    catch (Exception e)
    {
        Console.WriteLine("Error: {0}", e);
    }
}
  • Hello. Enter the method code Postagem(...) so we can help you.

  • Ready! I added the code...

  • Separate they work 100%, try to join them being a problem...

  • What is the value in the variable website when the exception occurs?

  • Error: System.Uriformatexception: Invalid URI: The format of the URI could not be determined.

  • This is the error... The website value is "System.Collections.Generic.List`1[System.String]"

  • I think the error is in: Postagem(website.Tostring()); But I couldn’t find another way ...

  • @Raulcorreia No main, put a Console.WriteLine(website); which value is returned?

  • I already fixed it, I used a simple code:

  • var total = website. Count(); for (int i = 0; i < total; i++) { Posting(website[i]); }

Show 5 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.