Tuesday, February 5, 2013

How to fix "The type or namespace name could not be found (are you missing a using directive or an assembly reference?)"

First of all, check if this assembly you already added into your project.

If yes, but still get this problem:
Go to Project Properties -> Application -> Target framework
Change this value to .NET Framework 4.0 from .NET Framework 4.0 Client Profile

Monday, February 4, 2013

Friday, February 1, 2013

The clearest way to express polymorphism


http://stackoverflow.com/questions/154577/polymorphism-vs-overriding-vs-overloading/154939#154939
public abstract class Human
{
   ...
   public abstract void goPee();
}

public class Male extends Human
{
...
public void goPee()
{
System.out.println("Stand Up");
}
}

public class Female extends Human
{
...
public void goPee()
{
System.out.println("Sit Down");
}
}
//Now we can tell an entire room full of Humans to go pee.

public static void main(String args)
{
ArrayList group = new ArrayList();
group.add(new Male());
group.add(new Female());
// ... add more...

// tell the class to take a pee break
for( Human person : group) person.goPee();
}

Wednesday, January 30, 2013

How to generate and download iCalendar file in ASP.NET MVC?

public ActionResult DownloadiCalendar()
        {
            MemoryStream output = new MemoryStream();
            StreamWriter writer = new StreamWriter(output, System.Text.Encoding.UTF8);
            writer.WriteLine(GetCalendarString());
            writer.Flush();
            output.Seek(0, SeekOrigin.Begin);
            return File(output, "text/calendar", "appointment.ics");
        }

        private string GetCalendarString()
        {
            string DateFormat = "yyyyMMddTHHmmssZ";
            DateTime startDate = DateTime.Now.AddDays(5);
            DateTime endDate = startDate.AddMinutes(35);
            string organizer = "foo@bar.com";
            string location = "My House";
            string summary = "My Event";
            string description = "Please come to\\nMy House";


            string calendar = "BEGIN:VCALENDAR";
            calendar = calendar + "\nVERSION:2.0";
            calendar = calendar + "\nMETHOD:PUBLISH";
            calendar = calendar + "\nBEGIN:VEVENT";
            calendar = calendar + "\nORGANIZER:MAILTO:" + organizer;
            calendar = calendar + "\nDTSTART:" + startDate.ToUniversalTime().ToString(DateFormat);
            calendar = calendar + "\nDTEND:" + endDate.ToUniversalTime().ToString(DateFormat);
            calendar = calendar + "\nLOCATION:" + location;
            calendar = calendar + "\nUID:" + DateTime.Now.ToUniversalTime().ToString(DateFormat) + "@mysite.com";
            calendar = calendar + "\nDTSTAMP:" + DateTime.Now.ToUniversalTime().ToString(DateFormat);
            calendar = calendar + "\nSUMMARY:" + summary;
            calendar = calendar + "\nDESCRIPTION:" + description;
            calendar = calendar + "\nPRIORITY:5";
            calendar = calendar + "\nCLASS:PUBLIC";
            calendar = calendar + "\nEND:VEVENT";
            calendar = calendar + "\nEND:VCALENDAR";

            return calendar;
        }

How run a ASP.NET project without Visual Studio and IIS configuration?

By ASP.NET development server:

"C:\Program Files (x86)\Common Files\microsoft shared\DevServer\10.0\webdev.webserver40.exe" /path:"C:\ProjectFolder" /vpath:/