Wednesday, May 19, 2010

Weird notepad error "Common Dialog error (0x3002)"

I was writing an Ant script that creates a simple ascii report and then opens it in Notepad.  I had the following in my Ant script:

<property name="report.file" value="${basedir}/Report-${timestamp}.txt"/>
...
<exec spawn="true" executable="notepad.exe">        
    <param line="${report.file}"/>
</exec>
     

After notepad.exe runs and shows the report, I tried to do a File > Save As, and got this error dialog:


I googled around for it, and all I was finding was people saying to reinstall this and that.  I started out fresh by doing a Start > Run > notepad.exe, and Save As worked just fine, so I figured it had to be something about the way I was launching it from Ant.

It turns out that ${basedir} evaluated to the full path of my project's basedir, with backslashes (\).  I was then appending a forward slash (/) and my file name.  Apparently this confused notepad when it tried to open the Save As dialog.

I fixed it by using the built-in ${file.separator} property that Ant inherits from Java, so my path now only contains backslashes.  My file name property now looks like this:

<property name="report.file" value="${basedir}${file.separator}Report-${timestamp}.txt"/>

This was on Windows XP SP3.

2 comments:

  1. Thanks for the write up. Helped me solve a similar problem. Running the command "notepad c:\\directory\\file.err" gives the same result, which is that the "file.err" will open correctly and then give you a Common Dialog error when you try to File->Save As. Changing the command to "notepad c:\directory\file.err" solves the problem.

    ReplyDelete
  2. Thank you for this post. I was trying to reset our default HOSTS file and it kept giving me that same error for the Common Dialog. THANK YOU SO MUCH!

    ReplyDelete