ASP.NET MVC select tag does not work unless specifically closed

I found out after a bit of pulling my hair out today that if you want to display a dropdown menu via a select tag inside a .cshtml page in your ASP.NET MVC project, you had better close the tag with </select>, because if you rely on the self closing tag (think <select />), then your asp-items will get eaten, along with other miscellaneous things.

Guidebook.me

Please check out my new travel tracking site, Guidebook.me. I have put a lot of time and effort into it, and while it is not done yet, I do have some big plans for it going forward. Let me know if you have any questions or comments.

Organizing a family photo collection using PowerShell, part 2

Just to recap from last month’s post, I have been given the chore of… Organizing a photo collection.

The files were on several computers and backups, so PowerShell on Windows 10 became the main vehicle with which I would try to bring this beast under control.

Plan for organizing a photo collection

  1. Bring photos together from all sources into one place
  2. Remove duplicate photos
  3. Organize photos by month and year

Step 3

Here is the PowerShell script that I used to organize the photos into folders by month and year. (WARNING: Any time you set up any kind of automated file process, make sure that you have backups.)

function fmove($SourceDir,$DestinationDir)
{
	$files = Get-ChildItem $SourceDir
	foreach ($file in $files) 
	{
		$Directory = $DestinationDir + "" + $file.LastWriteTime.Date.ToString('yyyy') + " " + $file.LastWriteTime.Date.ToString('MM')
		if (!(Test-Path $Directory))
		{
			New-Item $directory -type directory -Verbose
		}
		Move-Item $file.fullname $Directory -Verbose
	}
}
 
fmove -SourceDir "C:\Users\Me\Desktop\IntermediateDestination\" -DestinationDir "C:\Users\Me\Desktop\FinalDestination\"

There is not much going on here. The scripts iterates through all files in the source directory. For each individual file, there is a check to see if a folder exists with the last write year and month, creating it if necessary. And finally, the individual file is moved to that folder.

Once this script finishes, you will have a bunch of folders with files in them corresponding (roughly) to their date. However, please keep in mind that this might not be accurate if the files have been processed by other software.

BTW, Happy Birthday to the two dollar bill, issued on this date in 1976 to correspond with Thomas Jefferson’s birthday.

Organizing a family photo collection using PowerShell, part 1

If you are the only able bodied IT professional in a family, it means that you will be tasked with all sorts of demeaning and inane computer software and hardware questions, recommendations, and maintenance duties. Eventually, if you remain the solo IT person in a family long enough, you will be asked to perform one of the most daunting and thankless chores known to man… Organizing a photo collection.

You may be the only IT person in the family, but everyone else in the family has computers, digital cameras, and cell phones. All of these devices are capable of taking, storing, and more to the point, hiding digital imagery. And all of which have done so with varying degrees of success, which makes the job seem even more challenging.

Well friends, I am here to help. Recently I had to go through this very process with the myriad devices in use by my family. Instead of putting it off and grumbling about it, I decided to think this through and conquer the photo collection once and for all.

They had several different machines that were used to hold pictures, along with some backups of older machines that also had pictures on them. On the surface it seems like you would never be able to untangle the mess, but I thought about it for a few minutes and decided to apply the “divide and conquer” method to this conundrum. At my job, I have gained a newfound appreciation of PowerShell on Windows 10, so I decided to use PowerShell as a key component to my evil plans.

Plan for organizing a photo collection

  1. Bring photos together from all sources into one place
  2. Remove duplicate photos
  3. Organize photos by month and year

Now item #1 above sounds a bit easy at first glance. However, you have to keep in mind that cameras use names such as IMG_2209.JPG as the file names created. As a result, if you have taken a lot of photos with a lot of different cameras, you can get name collisions on files.

So first I needed to do was to get all of the backups and files from the disparate sources into one folder on my Windows 10 computer. Then, I would go through and find all the JPG files in the source location recursively one at a time, check to see if the file name exists in the destination, and if it does, add a number to it until it is unique, then copy the file to the destination. This would of course leave some duplicates in the destination that will be handled later.

Step 1

Here is the PowerShell script that I used to perform this task. (WARNING: Any time you set up any kind of automated file process, make sure that you have backups.)

function fcopy ($SourceDir,$DestinationDir)
{
	Get-ChildItem $SourceDir -Recurse | Where-Object { $_.PSIsContainer -eq $false } | ForEach-Object ($_) {
		$SourceFile = $_.FullName
		$DestinationFile = $DestinationDir + $_
		if (Test-Path $DestinationFile) {
			$i = 0
			while (Test-Path $DestinationFile) {
				$i += 1
				$DestinationFile = $DestinationDir + $_.basename + " " + $i + $_.extension
			}
		}
		Copy-Item -Path $SourceFile -Destination $DestinationFile -Verbose -Force
	}
}
 
fcopy -SourceDir "C:\Users\Me\Desktop\Source\" -DestinationDir "C:\Users\Me\Desktop\IntermediateDestination\"

In the last line of this script, you would fill in your source and destination directory. In my case, I had already pruned all of the files that were not JPG files out of all the source directories. If you do not do that, you would end up with file types you could then delete from the destination.

Step 2

Eventually the PowerShell script will finish, and you will have all your files in one folder. I then used a freeware Windows application that can go into a specified folder and find duplicate files. It then shows you which files it found as duplicates, and you can quickly delete all the unneeded duplicates. You should be able to find something workable with an internet search for duplicate file finder.

And finally, I highly recommend using the PowerShell ISE to work on and run your PowerShell script. It makes things go much smoother and can help you with any kind of questions or issues.

Please make sure to check back for my next installment of organizing a photo collection. I will cover how I massaged this massive file list into a more manageable structure. The folders wlll be organized by month and year that the picture was taken.

BTW, sort of in keeping the theme of today’s post, I hope everyone has a happy World Backup Day. In addition to being April Fool’s Day, tomorrow is also a good candidate for World Restore Day.

Mac Visual Studio Error: Address already in use

I have started to use the Mac version of Visual Studio more and more, and I must say I like it very much. But that does not mean it is not without its sharper edges.

Once in a while, when I am working on .NET web applications, something funky happens and when I try to run the project locally, I get the message:

Error: Address already in use

Here is how to fix this issue without having to go through some kind of insane reboot and/or ritual sacrifice.

First, find the process ID of the offending application in the terminal with this command, where you will replace 3306 with the port number that your local application runs on:

sudo lsof -iTCP -sTCP:LISTEN -P | grep :3306

This should give you the application and process ID (the first two items on the line) of the offender. Then, you enter this command, replacing 1234 with the second item from the data that the lsof command spit out:

kill -9 1234

BTW, Happy Belated 100th Birthday to the Grand Canyon. OK, not the actual canyon, but the National Park, which was designated such 100 years and 1 day ago. My advice to everyone is to stay at the El Tovar and eat breakfast at the restaurant, the sunrise is pretty astounding.

What are the odds?

So when I get into the office this morning, one of my Windows machines has rebooted and is happily waiting for me to log in, which interrupted a long running task that I had it working on when I left yesterday evening.

In my investigation to find out if this machine rebooted due to a power outage or due to a Windows Update, I filtered the system event log and found this entry:

I find it interesting that the computer picked that exact second to stop the event log service.

BTW, a posthumous Happy Birthday to John Belushi, who left us far too soon.

BingDebug

So I update my iOS apps on my iPhone this morning, and what do we have here…

If you fellers out there in Redmond need someone to help you get the reins on this iOS stuff, drop me a line.

BTW, Happy Human Rights Day. Sorry, I don’t feel like coming up with something better after the egg laid by the Steelers yesterday against Oakland.

C# .NET simple Async Await example from console application Main

I did a couple of posts a few years back about doing async/await in VB.NET, and now I had need of doing something similar with a C# .NET console application.

Here is what I put together to get it working. This is the contents of the main class for a C# .NET console application, but you should be able to adapt the code to whatever need you have.

using System;
using System.Net.Http;
using System.Threading.Tasks;
 
namespace SimpleAsync
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Simple async");
 
            try
            {
                LengthyAsyncTask().Wait();
            }
            catch (Exception ex)
            {
                Console.WriteLine("There was an exception: " + ex.ToString());
            }
 
            Console.WriteLine("Press enter to quit application...");
            Console.ReadLine();
        }
 
        static async Task LengthyAsyncTask()
        {
            var response = await GetWebPage("https://www.dosomethinghere.com");
            Console.WriteLine("Response: " + response);
            // do something here with the response
        }
 
        static async Task<string> GetWebPage(string url)
        {
            var client = new HttpClient();
            var response = await client.GetAsync(url);
            var responseString = await response.Content.ReadAsStringAsync();
            return responseString;
        }
    }
}

BTW, Happy Anniversary to The Wall and Thriller, both seminal works of artistry from music’s golden age, released this day in 1979 and 1982, respectively. Darkness falls across the land… And how can you eat your pudding when you haven’t eaten your meat?

App crashes on iOS Simulator without debugging

If your app in the iOS Simulator works when debugging with Xcode, but the very same app crashes if you try to launch it without debugging, check your app for a framework listed under Linked Frameworks and Libraries, but not listed under Embedded Binaries. Once the framework shows up in both places, deploy the app again by debugging with Xcode, and then stop the debugging and try to launch it again on the Simulator.

BTW, Happy Birthday to Randall Munroe, creator of the xkcd web comic.

Visual Studio 2017 launches to a black or invisible screen, part 2

It turns out that disabling the Intel and Nvidia drivers on my Windows notebook computer are not really sufficient to fix the issue when Visual Studio 2017 launches to a black or invisible screen, as by doing this, I lost the ability to connect an external monitor to the HDMI port on the computer. Super bummer.

A bit more digging through the interwebs led me to this answer to a question on Stack Overflow:

White screen while opening visual studio

Basically, I re-enabled the Intel and Nvidia display options, then opened the Nvidia Control Panel by right-clicking on the desktop, selected Manage 3D Settings and changed the Preferred graphics processor selection from Auto-select to High-performance NVIDIA processor. Now everything is back to working the way I would like it to.

BTW, there are no birthdays today worthy of mention (cough, cough), so Happy International Left Handers Day!