Category Archives: Guides

How to Open the Same File Twice in Visual Studio

Hey everyone,

Today I was working on a fairly large class and needed to compare two different areas of code. I’m used to using text editors such as notepad++ and sublime where I would normally just open the file multiple times. It turns out that Visual Studio has a similar feature, although it’s admittedly a lot less intuitive:

– Open the file you want to duplicate and make it the active tab (just click on it somewhere)
– Select window from the menu up the top
– Click New Window

This will duplicate your active tab. To place them side by side simply right click on one of them and then select ‘New Vertical Tab Group’.

Thanks to this Stackoverflow post for the solution:

View Generated SQL in Entity Framework (EF)

Hey everyone,

Just a quick post on how to view the generated sql in entity framework. To start with, just add the following line to your db context constructor:

public class TestDbContext : DbContext
        public TestDbContext() : base("name=TestDbContext")
            this.Database.Log = s => System.Diagnostics.Debug.WriteLine(s); //This line

With this line added, you should now be able to see all of your generated sql in the output window.

    [Project1].[VidId] AS [VidId], 
    [Project1].[CreatedAt] AS [CreatedAt], 
    [Project1].[CHECK] AS [CHECK], 
    [Project1].[SourceCheck] AS [SourceCheck]
        [Extent1].[VidId] AS [VidId], 
        [Extent1].[CreatedAt] AS [CreatedAt], 
        [Extent1].[CHECK] AS [CHECK], 
        [Extent1].[SourceCheck] AS [SourceCheck]
        FROM [dbo].[Vids] AS [Extent1]
        WHERE [Extent1].[VidId] < @p__linq__0
    )  AS [Project1]
    ORDER BY [Project1].[VidId] DESC
-- p__linq__0: '535' (Type = Int32)
-- Executing at 28/06/2014 5:00:16 PM +10:00
-- Completed in 0 ms with result: SqlDataReader

If you’re not using EF6, there were a few other options where I came across this solution:

How to Open the Same File Twice in Visual Studio

Hey everyone,

I was working on a fairly large class in visual studio and having a bit of trouble comparing two different areas within it. Thankfully, StackOverflow knew of a way to make things a lot easier – open the same file twice:

– With the tab you want to duplicate currently active, select Window from the menu
– Click new window
– On the new window, right click and select ‘New Vertical Tab Group’ from the drop down

How to stop text taking up more than one line – CSS

Hey everyone,

Just a quick post on how to stop text taking up more than one line using only CSS:

.truncate {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;

You can check it out using this fiddle:
There’s also a great StackOverflow post:

Duplicate type name within an assembly. – Entity FrameWork (EF)

Hey everyone,

I ran into this error message while trying to debug a project today:

“Duplicate type name within an assembly.”


The workaround to this was actually pretty weird. Remove all of your breakpoints that appear before this exception and place one after it instead. That’s it!

A bit of a weird issue, but according to the StackOverflow post where I found the solution Microsoft are aware of it:

Decimal Values for Bitcoin C#

Hey everyone,

Just linking to a few Stackoverflow posts that have helped me out with bitcoin precision requirements:

Precision Values

Setting up Decimal Precision in MVC4+

Refresh a Page with JavaScript

Hey everyone,

Just a quick post on how to force a page refresh with JavaScript (no jQuery required):


Note that the reload function accepts a boolean parameter that can be used for force a server refresh. Alternatively, it just defaults to the cache.

Checkout this Stackoverflow post for more info:

Detecting File Size with jQuery

Detecting FileSize – jQuery

Hey everyone,

Just a quick post on how to detect a file’s size with jQuery. I’m currently using a version of this for basic client side validation:

<form action="upload" enctype="multipart/form-data" method="post">
    Upload image:
    <input id="image-file" type="file" name="file" />
    $('#image-file').bind('change', function() {
        var fileSize = this.files && this.files.length > 0 && this.files[0].size ? this.files[0].size / 1024 / 1024 : 0;
        if(fileSize > 0){
            $('body').append('<div class="file valid">' + fileSize + ' MB</div>');  
            $('body').append('<div class="file invalid">' + fileSize + ' MB</div>'); 
padding: 5px 7px;
border-radius: 3px;
background-color: green;
color: white;
margin: 5px;
background-color: rgb(127, 197, 127);
background-color: rgb(197, 127, 127);

Here’s the link to the full fiddle:

There’re also a whole heap of other options listed on this StackOverflow post if you’re chasing something a bit more robust:

My Selling Tools Option Missing – PayPal

Hey everyone,

For some reason the “My Selling Tools” option is now missing on my production account. Unfortunately the only way to get around this that I’ve come across is to access the required features directly. For example:

API Access:

If you’ve got any other links that might be useful please let me know and I’ll add them.

Rendering a View to a String – Email Templates in MVC4

Hey everyone,

This is just a short post showing how to render views as strings. I’ve used this as a quick way to generate email templates. The logic to render a view as a string is as follows:

public static string RenderRazorViewToString(Controller controller, string viewName, string content)
            controller.ViewBag.Content = content;
            using (var sw = new StringWriter())
                var viewResult = ViewEngines.Engines.FindPartialView(controller.ControllerContext, viewName);
                var viewContext = new ViewContext(controller.ControllerContext, viewResult.View, controller.ViewData, controller.TempData, sw);
                viewResult.View.Render(viewContext, sw);
                viewResult.ViewEngine.ReleaseView(controller.ControllerContext, viewResult.View);
                return sw.GetStringBuilder().ToString();

The Email Template: Views/Emails/DefaultTemplate

    Layout = null;
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Easy Carts</title>
<body bgcolor='#f5f6f7' style='font-family: Arial, Helvetica, sans-serif;'>
    <!-- Wrapper -->
    <table width='100%' align='center' bgcolor='#f5f6f7' cellpadding='40' style='border-radius:3px;'>
                <table width='500px;' align='center' bgcolor='#FFFFFF' cellpadding='15'>
                        <td style='font-size:13px;' align='left'>                           
        <tr align='center'>
            <td align='center'>
                <a href="">
                    <img src='' />

In your controller:

public String TestEmail(String content)
            Email email = new Email() {
                To = "",
                From = Email.Fields.From.NoReply,
                Body = content,
                Subject = "Test",
                TemplateName = @"~\Views\Emails\DefaultTemplate.cshtml",
                UseTemplate = true
            return email.Body.ToString();

If you looking to implement this with your emails, note that it builds on top of the email class we created back in this post:

If you’re just going to be using it directly within the controller, using the original code from over StackOverflow will probably be your best bet: