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.– Omni
Ready! I added the code...
– Raul Correia
Separate they work 100%, try to join them being a problem...
– Raul Correia
What is the value in the variable
website
when the exception occurs?– Omni
Error: System.Uriformatexception: Invalid URI: The format of the URI could not be determined.
– Raul Correia
This is the error... The website value is "System.Collections.Generic.List`1[System.String]"
– Raul Correia
I think the error is in: Postagem(website.Tostring()); But I couldn’t find another way ...
– Raul Correia
@Raulcorreia No
main
, put aConsole.WriteLine(website);
which value is returned?– stderr
I already fixed it, I used a simple code:
– Raul Correia
var total = website. Count(); for (int i = 0; i < total; i++) { Posting(website[i]); }
– Raul Correia