
Back to Blog index.
Sometimes, you want to write (DOS) batch files (those with .BAT or .CMD extensions) to automate certain tasks. I today learned a neat little trick using the %CD% environment variable. This variable always holds the current directory where the batch file is. You can use this to manipulate paths, or save the path for later use into another environment variable.
Of course, since Windows XP you can also use the pushd and popd (push and pop directory) commands to save and restore the current directory/path. I learned these commands at the time I was still using 4NT, but now with Windows XP and later, these commands are part of the CMD.EXE command interpreter.
Adobe has just recently updated my favorite photo management/editing utility Lightroom: a new, free version 1.1 update is available for download from Adobe's support web site.
Improvements include better support for multi-computer work, better noise reduction and sharpness settings and Windows Vista support. Sounds great! There's also available a "What's New" type of article about the LR 1.1 update on Digital Outback Photo.
If you need something to spend your rainy summer holidays (not that they'd be needed!) in an useful manner, there are three Finnish Microsoft white papers available for developers. There are:
The two last ones are hosted on the ITpro.fi site which recently started hosting the "Arkkitehtiryhmä" as well.
Two simple Windows tips that I confess didn't know previously: in Windows XP and Vista, you can double-click the windows' title bar to maximize the window. This trick is of course well-known and has existed I think since Windows 3.0, but what was new to me is that if you hold down Ctrl while double-clicking the title bar, you can fully maximize the window. This would be the same as pressing F11 on Windows basic shell windows and Internet Explorer. To return to the normal view, simply press F11.
Another tip is regarding Excel. If you have cells in Excel, say, in a row (top-down) but want them in columns instead, use the Edit/Paste Special/Transpose command. Yes, I've used Paste Special a lot ("Unformatted" is my most-needed option), but I've never noticed the Transpose option. Try it, works like a charm!
I learned about these tricks from the Microsoft AtHome and Office sites here and here.
Happy Midsummer to everyone! I'm off to my weekend-long holiday to watch the bonfires and cooking by the BBQ, but back again on Monday. Have a great weekend, enjoy the sun and longest days of the year, and thanks for stopping by!
Sometimes, you need to be able to detect which version (if any) of the .NET Framework is installed on your PC. If you want to do this by hand, then Microsoft's KB article 318785 shows you how to do it. Currently, the article covers .NET Framework versions 1.0 to 2.0.
The April 2007 issue of MSDN Magazine has an article about tracking Visual Studio Team System (VSTS) / Team Foundation Server (TFS) work items. The article talks for example about WIQL queries, which is an SQL-like language. Go check it out!
Yesterday I ran a Borland/CodeGear webcast about Windows Vista and using Delphi to develop application for this new operating system. The audio+PowerPoint session was recorded, and you are able to hear the recording on borland.interwise.com. I hope you will find this recording (in Finnish) useful.
I just learned that Microsoft has announced the first CTP (Community Technology Preview) of "Acropolis", a toolkit to allow business application developers to use Windows Presentation Foundation (WPF) to better develop applications. This toolkit can be downloaded from Microsoft Downloads.
From the toolkit's documentation:
Code Name "Acropolis" is a toolkit for creating modular, business-focused Windows client applications. "Acropolis" builds on the.NET Framework, and includes a run-time framework, design-time tools, and out-of-the-box functionality.
Sounds interesting. In fact, tons of stuff are coming from Microsoft for developers alone later this year. The forth-coming autumn will be action packed, that's for sure!
On Monday I blogged about Visual Studio 2005 Team System and Team Foundation Server, and decided to continue today. That is, once you've just installed Team Foundation Server (TFS), and try to connect to a newly-created Team Project from Team Explorer, you might get the following error:
The request failed with HTTP status 403: TF53011: VIRTUAL-W2K3\Jani Järvinen is not a licensed user.
On the screen, this looks like this (note the error in showing special characters):

To fix this error, you will need to add your own user account to the Team Foundation Server Installed User's group under Team Foundation Server Settings. To do this, in Team Explorer, right-click your server, and choose the command Team Foundation Server Settings/Group Membership:

In the Global Groups dialog box, select the [SERVER]\Team Foundation Server Licensed Users, and then click Properties:

Finally, a dialog box is displayed showing the users that belong to this group. By default, only the local Administrator and the "TFSSETUP" user accounts are part of this group. To fix the problem, just add your account to the list:

Note that if you are using Team Foundation Server Workgroup Edition, only five (5) users can be added to the list, not more. In any case, adding yourself to the list will solve the issue.
If you are using Visual Studio 2005 Team System (VSTS), you are most probably also using Team Foundation Server as your version control and team workspace. However, in certain cases it can happen that once you've installed TFS and try to connect to it using Visual Studio/Team Explorer, you will get the following error message when creating your first Team Project:
TF30177: Team Project Creation Failed New Team Project Wizard encountered the following error and could not continue. Error Unable to connect to the specified SQL Server Reporting Services at 192.168.218.129. Explanation The Project Creation Wizard was not able to connect to the SQL Server Reporting Services at 192.168.218.129. The reason for the failed connection cannot be determined at this time. Because the connection failed, the wizard was not able to complete creating the SQL Server Reporting Services site.
The error message dialog box looks like this:

Now, why did this happen? The message "the reason for the failed connection cannot be determined at this time" isn't very helpful. However, most probably this error is caused by DNS problems, especially if you are using virtual machines (VMware or Virtual PC/Server, it doesn't matter) to host your TFS server.
To work around or fix this problem, make sure your client (Visual Studio/Team Explorer) can properly resolve the name of the TFS server. That is, your TFS server host might be named "TFSSERV1", but your client PC might not return the correct IP address for the server, or might not return anything at all. In these cases, you can correct the DNS entry, or if no DNS server is present, flush the DNS cache on the client, or edit the "hosts" file on the client PC's (C:\WINDOWS\system32\drivers\etc\hosts by default) and add the correct entry there. This should solve the error and allow you to create your team projects normally.
Keywords: How To, Howto, Microsoft Visual Studio 2005, Team Foundation Server, TFS, Team System.
In the .NET newsgroups, the user "EnerPeter" asked whether it would be possible to derive a new class from an array of bytes (specifically byte[] or more generically System.Array) to override the default ToString() method. Here's my answer almost verbatim.
Unfortunately, the short answer is no. By looking at the documentation for Array, it might appear that you could derive your own types from System.Array, but in fact all (at least all I have used) .NET languages/compilers refuse to allow this. For example, the C# compiler fails with the error message "NN cannot derive from special class System.Array".
However, even if you could do this, deriving would be more difficult than it sounds at first, since the compiler actually does quite a lot of so-called "compiler magic" for you when you use a seemingly simple construct like this:
byte[] myBytes = { 12, 83, 62 };
Since System.Array is an abstract class, the compiler must first create a derived type behind the scenes. Also, there's code needed to initialize the array -- you can see all this when you use ILDASM for example to view the generated MSIL (intermediate language) code.
Finally, if you would derive your own byte array class, it would not work the same as regular arrays. As noted by the MSDN documentation of the Array class:
"However, only the system and compilers can derive explicitly from the Array class. Users should employ the array constructs provided by the language."
So the bottom line is that you cannot do it. With forthcoming C# 3.0 extension methods you could make things look more convenient, but in the end your option is to write some code to convert the byte array to a string. See MSDN for more information about extension methods in C# 3.0.
Finally, here's a simple example of a method that converts a byte array to a proper string:
byte[] myBytes = { 72, 101, 108, 108, 111, 33 };
string str = System.Text.Encoding.ASCII.GetString(myBytes);
MessageBox.Show(str);
This would show: "Hello!". If you wanted to get the real bytes instead, then you could use something like this:
MessageBox.Show(BytesToString(myBytes));
private string BytesToString(byte[] bytes)
{
StringBuilder buffer = new StringBuilder();
buffer.Append("{ ");
foreach (byte b in bytes)
{
if (buffer.Length > 2) buffer.Append(", ");
buffer.Append(b);
}
buffer.Append(" }");
return buffer.ToString();
}
This would show: "{ 72, 101, 108, 108, 111, 33 }".
Hope this helps!
If you use C# to develop a Windows Service application (a "service"), you will probably use the InstallUtil utility for initial installations on test machines. If you are like me, you do such tests inside virtual machines.
Now, I have a set of virtual machines ready-made, and most of them don't belong (are member of) any domain; instead they just belong to the default workgroup. In such a situation, InstallUtil will require you to prefix your user account name under which the service is going to run with your computer name. If you do not, you will see the following error message:
An exception occurred during the Install phase. System.ComponentModel.Win32Exception: The account name is invalid or does not exist, or the password is invalid for the account name specified. The Rollback phase of the installation is beginning.
Depending on your installer classes/code, you might wish to prompt the user for the credentials under which your new service will run. If you simply type in a name of a local account, say, "Administrator", you will get the above error message. To remedy this situation, use a either one of these constructs:
COMPUTERNAME\Administrator .\Administrator
This will fix the problem. InstallUtils is developed with Active Directory and domain accounts in mind, and thus expects the DOMAIN\ACCOUNT construct. But you can substitute the dot "." instead of the domain if your test machine isn't part of a domain.
It's official: Microsoft has decided to name Visual Studio's forthcoming "Orcas" version simply as Visual Studio 2008. The announcement was made at the TechEd 2007 conference. Although the name is far from surprising, I do like it. It follows the trend set by other Microsoft products (like Office, SQL Server and server operating systems), and most of all, keeps things simple. The products pages on MSDN are not yet updated, but I'd imagine they'd soon be.
Adobe's Lightroom uses SQLite as the database engine. That said, the file "Lightroom Database.lrdb" is simply a SQLite 3 database, and by using a SQLite browser, you can easily execute SQL queries againts the database. Here's an example:
SELECT f.absolutePath FROM AgLibraryTag t, AgLibraryTagImage i, Adobe_imageFiles f WHERE (t.name = "John Doe") AND (t.kindName = "AgKeywordTagKind") AND (i.tag = t.id_local) AND (i.image = f.image)
This query would fetch the absolute paths of all images which have been tagged with the tag "John Doe". As you can see, there are three tables that are related to each other with the "id_local" field, and are thus part of the join. As you can see, Lightroom's database isn't a black box. :-) Great!
Some photography for a change: Magnum photography has put up an online exhibition about their 60 years of best-class photography. As you can guess, only the top photos get to be published. Motto: see, understand and learn from the best!
This is a bit old news, but about two weeks about ITpro.fi site got updated into the RTM version of SharePoint 2007. For example, the search function now works properly, and also previous security issues with for example group membership should now be gone. Enjoy! The software development blog is also available if you understand Finnish.
The .NET base class library has extensive support for cryptography, and you might for example need to encrypt a file with, say, the Rijndael (AES) algortihm. For that purpose, .NET supports the RijndaelManaged class, for instance. But, this and many other security classes require you to pass in a byte array for a key and the initialization vector (IV). How could you come up with this data in code? Hard-coded values are of course no good, and that's why there's for example a helper class called Rfc2898DeriveBytes. This class uses RFC 2898 to create a key and IV from a set of bytes, which -- you guessed it -- can be the user's password. Here's how to do it:
using System.Security.Cryptography;
...
public static void GetKeyAndIvFromPassword(string password, out byte[] key, out byte[] iv)
{
const int keyBytes = 256 / 8;
const int ivBytes = 128 / 8;
//TODO: Change salt value to something else
byte[] salt = { 34, 234, 192, 19, 98, 214, 201, 84, 175, 74, 163, 132 };
Rfc2898DeriveBytes keyGen = new Rfc2898DeriveBytes(password, salt);
key = keyGen.GetBytes(keyBytes);
iv = keyGen.GetBytes(ivBytes);
}
This little function should solve many of your needs. Just remember to change your salt value to something different, or better yet, use truly random data.
› Blog Archive