Mvc DisplayAttribute Name based on resources

If you try to use resources in the property Name like this:

    public class ForgotViewModel
        [Display(Name = Resources.Email)]
        public string Email { get; set; }

You will get the error “An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type”

And this error is correct. So to use resources you will have to do something like this:

    public class ForgotViewModel
        [Display(Name = "Email", ResourceType=typeof(Resources))]
        public string Email { get; set; }

Now in your Resources type you will have to make sure that the Email property exists and that it’s Access Modifier is Public.

To may all Resources Public double click in your resx files and locate the drop box “Access Modifier” and change it’s value to Public.


Mvc5 EmailService implementation

This my generic EmailService Implementation. From here I can configure any email service like gmail.

public class EmailService : IIdentityMessageService
        private const string ConfigurationEmailIsBodyHtml = "EmailIsBodyHtml";

        public static string From { get; set; }
        public static string UserName { get; set; }
        public static string Password { get; set; }
        public static string Host { get; set; }
        public static int Port { get; set; }
        public static bool EnableSsl { get; set; }
        public static bool IsBodyHtml { get; set; }
        public static bool UseDefaultCredentials { get; set; }
        public static SmtpDeliveryMethod DeliveryMethod { get; set; }

        static EmailService()
            IsBodyHtml = ConfigurationManager.AppSettings[ConfigurationEmailIsBodyHtml].ToOrOther<bool>(true);

            SmtpSection section = (SmtpSection)ConfigurationManager.GetSection("");

            if (section != null)
                From = section.From;
                Host = section.Network.Host;
                Port = section.Network.Port;
                EnableSsl = section.Network.EnableSsl;
                UserName = section.Network.UserName;
                Password = section.Network.Password;
                DeliveryMethod = section.DeliveryMethod;
                UseDefaultCredentials = section.Network.DefaultCredentials;


        public Task SendAsync(IdentityMessage message)

            var smtp = new SmtpClient
                Host = Host,
                Port = Port,
                EnableSsl = EnableSsl,
                DeliveryMethod = DeliveryMethod,
                UseDefaultCredentials = UseDefaultCredentials,
                Credentials = new NetworkCredential(UserName, Password)

            using (var smtpMessage = new MailMessage(From, message.Destination))
                smtpMessage.Subject = message.Subject;
                smtpMessage.Body = message.Body;
                smtpMessage.IsBodyHtml = IsBodyHtml;
                return smtp.SendMailAsync(smtpMessage);

            // Plug in your email service here to send an email.
            //return Task.FromResult(0);

Gmail configuration:

      <smtp deliveryMethod="Network" from="">
        <network host=""


Import CSV in MySql Workbench

This is a quick tip on how to import a csv with data into one of your tables.

1º Open MySql Workbench

2º run the following query

On linux:

load data local infile ‘/path/to/your/file.csv’ into table dbName.tableName fields terminated by ‘,’ enclosed by ‘”‘ lines terminated by ‘\n';

On Windows

load data local infile ‘c:\\path\\to\\your\\file.csv’ into table dbName.tableName fields terminated by ‘,’ enclosed by ‘”‘ lines terminated by ‘\n';


Download all Build 2014 videos

As you probably should know by now Build 2014 it’s over and it’s time to download the videos.

In this demo I will use MP4 high quality rss feed but it’s the same for other formats.

    class Program
        public static XmlDocument getXMLDocumentFromXMLTemplate(string inURL)
            HttpWebRequest myHttpWebRequest = null;     //Declare an HTTP-specific implementation of the WebRequest class.
            HttpWebResponse myHttpWebResponse = null;   //Declare an HTTP-specific implementation of the WebResponse class
            XmlDocument myXMLDocument = null;           //Declare XMLResponse document
            XmlTextReader myXMLReader = null;           //Declare XMLReader

                //Create Request
                myHttpWebRequest = (HttpWebRequest)HttpWebRequest.Create(inURL);
                myHttpWebRequest.Method = "GET";
                myHttpWebRequest.ContentType = "text/xml; encoding='utf-8'";

                //Get Response
                myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();

                //Now load the XML Document
                myXMLDocument = new XmlDocument();

                //Load response stream into XMLReader
                myXMLReader = new XmlTextReader(myHttpWebResponse.GetResponseStream());
            catch (Exception myException)
                throw new Exception("Error Occurred in AuditAdapter.getXMLDocumentFromXMLTemplate()", myException);
                myHttpWebRequest = null;
                myHttpWebResponse = null;
                myXMLReader = null;
            return myXMLDocument;

        static void Main(string[] args)
            XmlDocument doc = getXMLDocumentFromXMLTemplate("");

            XmlNodeList list = doc.GetElementsByTagName("enclosure");
            StringBuilder sb = new StringBuilder();

            foreach(XmlNode node in list)
                sb.AppendLine("wget " + node.Attributes["url"].Value);

            string str = sb.ToString();
            //save the string to a file

The result will be a string like this:




just save that string to a cmd file and you are ready to download all the videos.