Mostrando entradas con la etiqueta C#. Mostrar todas las entradas
Mostrando entradas con la etiqueta C#. Mostrar todas las entradas

Invocar un método por su nombre en C# con Invoke

   Type thisType = this.GetType();

En el caso en que sea un método privado, agregar estos parametros:

   MethodInfo theMethod = thisType.GetMethod("nombre-del-metodo", BindingFlags.NonPublic | BindingFlags.Instance);

Si el método es público:

   MethodInfo theMethod = thisType.GetMethod("nombre-del-metodo");

Para ejecutarlo: (observar que param es el parametro que se le pasa al metodo:

   var msg = (TipoDeDatoQueDevuelveElMetodo)theMethod.Invoke(this, new[] { param });

Ej, si se llama a un actionresult:

   var msg = (TipoDeDatoQueDevuelveElMetodo)theMethod.Invoke(this, new[] { param });


Acceder a blogger mediante Google API

Descargar Google Data API Setup(1.4.0.2).msi 

Código de ejemplo, agrega un post asignándole dos etiquetas:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Google.GData.Client;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] labels = {"label1", "label2"};        //labels que le quiero poner al post

            AddPost("titulo1", "body html", labels);     //titulo, cuerpo html y array de labels
        }

        public static bool AddPost(string title, string bodyHTML, string[] labels)
        {
            Service service = new Service("blogger", "");
            service.Credentials = new GDataCredentials("", "");
            AtomEntry newPost = new AtomEntry();
            newPost.Title.Text = title;
            newPost.Content = new AtomContent();
            newPost.Content.Content = bodyHTML;
            newPost.Content.Type = "html";
            foreach (string label in labels)
            {
                AtomCategory cat = new AtomCategory();
                cat.Scheme = new Uri("http://www.blogger.com/atom/ns#");
                cat.Term = label;
                newPost.Categories.Add(cat);
            }
            AtomEntry response = null;
            try
            {
                response = service.Insert(new Uri("http://expressraider.blogspot.com/feeds/posts/default"), newPost);
            }
            catch (GDataRequestException exception)
            {
                if (exception.ResponseString == "Blog has exceeded rate limit or otherwise requires word verification for new posts")
                {
                    return false;
                }
                else
                {
                    throw exception;
                }
            }
            if (response == null)
            {
                throw new Exception("Error inesperado");
            }
            return true;
        }

    }
}

Consulta con conexión DSNLess a MySql desde C#

using System.Data.Odbc;


string odbcconnstr = "Driver={MySQL ODBC 3.51 Driver};Server=servidor;Database=base;User=usuario;Password=password;Port=puerto;Option=4";

OdbcConnection conn;

conn = new OdbcConnection(odbcconnstr);
conn.Open();
OdbcCommand cmd = new OdbcCommand();
cmd.Connection = conn;
cmd.CommandText = "select * from tabla";
OdbcDataReader dr = cmd.ExecuteReader();

while (dr.Read())
{
   // codigo                   
}

conn.Close();