Jeff Widmer's Blog
ASP.NET, ASP.NET MVC, C#, VB.NET, IIS7, Windows Forms, VB6, ASP 3.0
-
Batch file that monitors the number of files in a directory
Sometimes the fastest and easiest way to complete a task is a good old MS-DOS batch (.bat) file. A friend recently needed to get a quick fix in place for their production machine.
“I need to whip up a batch file that monitors the number of files in a directory. Basically, I want to see if there are 100 files in a directory and then start and stop a service to do some quick cleanup.”
The For command can be used to loop through the files in a folder and get a count and then do something based on that number.
@ECHO OFF
SETLOCAL
SETLOCAL ENABLEDELAYEDEXPANSIONSET count=0
for %%o IN (D:\temp\*.*) DO (
echo %%o
SET /A count=count + 1
)echo %count%
IF "%count%"=="100" ECHO NET STOP MyApp
ENDLOCAL ENABLEDELAYEDEXPANSION
ENDLOCALTechnorati Tags: Batch Files,MS-DOS -
How to prevent scrollbar jump in Firefox and Chrome
On Firefox and Chrome if the content of a page is not longer than the window, then the right scrollbar is not displayed, and likewise if the content of the page is longer than the window then the right scrollbar is displayed. This makes perfect sense except that for websites that are center justified (which is most websites these days) then the center content will appear to jump to the left when switching from a page with content that is shorter than the window to a page with content that is longer than the window. This jump can be a bit annoying since the header shift makes your eyes think something may have changed in the header (at least it does for me) so a rescan of the header occurs.
The best way to explain this is by an example. The Vaasnet home page is a short page with all of the content fitting within a single window (or above the fold):
Now switch to the Vaasnet Features page (which has content that is longer than the window or pushes below the fold) and the right scroll bar appears. This causes the entire page to shift to the left which looks somewhat not esthetically pleasing. It is hard to show in screen shots but it is much more apparent when browsing the site and the shift in the header and navigation is apparent and somewhat irritating.
There is a simple css fix to correct this problem. Just add the following style to your site:
html {overflow-y:scroll;}
Now the vertical scrollbar will always show on the right and you have eliminated the jump in the page content. (Notice the vertical scroll bar on the right hand side of the Vaasnet home page now.)
Technorati Tags: Scrollbar Jump in Firefox and Chrome,HTML Tips and Tricks -
HTML Tips and Tricks: Use div with border in place of hr
I am by no means an expert with html or css. Frequently I run into html or css issues that take me forever to get beyond. Recently I had an issue with a horizontal rule (<hr />) having extra padding in Internet Explorer. For some reason I could not figure out where the padding was coming from.
I don’t think this was an IE issue since a completely clean sample of html did not show the hr padding (or margin) problem in Internet Explorer. But for some reason the <hr> tag would not adhere to any padding or margin styling that I tried in Internet Explorer as it would in FireFox or Chrome.
After struggling with this for a while I realized I could use a <div> with a bottom border in place of the <hr>. It worked very nicely and gave me more control over the dividing line that I was trying to place in my user interface.
<div style="height:1px; width: 100%; border-bottom:solid 2px #ccc;" />
Maybe this will help any of the other HTML/CSS impaired developers out there.
Technorati Tags: HTML Tips and Tricks -
Excellent “What is Windows Azure?” Video
Technorati Tags: What is Windows Azure? -
Line-breaks and carriage returns (\r \n) are invalid in email subject
I received this exception when sending an email using System.Net.Mail.MailMessage:
"The specified string is not in the form required for a subject."
System.ArgumentException: The specified string is not in the form required for a subject.
at System.Net.Mail.Message.set_Subject(String value)
at System.Net.Mail.MailMessage.set_Subject(String value)The subject line of the email I was sending had a carriage return and line break in it so it made sense that this would be an invalid subject line.
And I was able to confirm that a check is made on the subject line to make sure there are not Carriage Returns or Line Feeds when the MailMessage.Subject property is set, but also that these are the only characters checked for.
To remove the line breaks and carriage returns I just did a simple find and replace:
subject= subject.Replace("\n", " ").Replace("\r", " ");
Technorati Tags: System.Net.Mail.MailMessage.Subject -
What is the difference between Hyper-V Manager Save and Pause?
The Hyper-V Management Console has several different actions you can take for a running virtual machine. Most are self-explanatory but I never quite new the difference between Save and Pause.
I always used Save to stop a virtual machine and save the current state of the virtual machine. But I did not understand how Pause would differ from Save. I finally went hunting for exactly what Pause does and found it in this Technet Article: Step 6 (Optional): Test Snapshots, Pausing, and Saving.
“You can also pause or save a virtual machine in a given state. When you pause or save a virtual machine, it stays in its current state for as long as you want.
Although pausing a virtual machine does not free up the memory that is allocated to that virtual machine, it frees up main processor resources. Saving a virtual machine frees up memory and main processor resources so that they can be used by other virtual machines or by the virtualization server.”So Pausing will hold the Virtual Machine in the current state in was in when you hit the Pause button and also keep it in RAM (continuing to use a valuable resource) but frees up the processor. Saving will also hold the virtual machine in the current state but it frees up the processor and RAM too.
So I think this would be true then:
Saving a virtual machine is to Hibernate as Pausing a virtual machine is to Sleep. -
SQL Server encountered error 0x80070422 while communicating with full-text filter daemon host (FDHost) process.
When trying to do a full text search with SQL Server 2008 I received this error:
SQL Server encountered error 0x80070422 while communicating with full-text filter daemon host (FDHost) process. Make sure that the FDHost process is running. To re-start the FDHost process, run the sp_fulltext_service 'restart_all_fdhosts' command or restart the SQL Server instance.
I was able to track this down to the SQL Full-text Filter Daemon Launcher service being disabled. Enabling and starting the service resolved the issue for me.
It is interesting to note that the service is set to a Startup Type of Manual but after a restart of my machine the service is started, so SQL Server 2008 must be starting it. Having the service disabled probably prevented SQL Server from starting it the first time I went to run a full-text search.
See this post (SQL Server encountered error 0x80070422 (FIXED)) for the same error message but I did not do all the steps he did (I just enabled and started the service).
Technorati Tags: SQL Server Full-text Search -
How to change the Target Framework Version for a Visual Basic Project
Today I received the following warning message from Visual Studio while adding a reference in a Visual Basic project:
The Target Framework version for the project ‘XXXX’ is higher than the current Target Framework version.
Would you like to add this reference to your project anyway?This warning message makes complete sense since the Visual Basic project I was working on is targeting the .NET Framework 2.0 and the project that was being referenced targeted the .NET Framework 3.5. The only issue was that I was not able to figure out how to change the Target Framework Version in a Visual Basic project.
In a C# project it is pretty easy; right-click on the project and choose properties and in the Application tab (vertical tab) you will see the Target Framework dropdown box:
But in Visual Basic it is hidden. Here is where I found how to change the Target Framework version after searching for a bit:
Right-click on the project and choose properties and then select the Compile tab (vertical tab).
At the bottom of the Project > Compile tab you will find an Advanced Compile Options… button.
In this dialog called the Advanced Compiler Settings is where you will find how to change the Target Framework version for Visual Basic.
-
GDI+ Error when converting Tiff to Jpeg: Parameter is not valid
One of the web applications that I work on is Instant Church Directory, a website that helps churches create a church photo directory. Since the main focus of the application is to create a photo directory, customers are uploading all sorts of images into Instant Church Directory and the application needs to correctly convert and store the images and insert them in the final output, which is a PDF.
Since the web application was launched in September 2008 we have had an issue with some Tiff images that are uploaded and throw a System.ArgumentException when the image is converted to a Jpeg.
System.ArgumentException: Parameter is not valid. at System.Drawing.Image.Save(Stream stream, ImageCodecInfo encoder, EncoderParameters encoderParams) at System.Drawing.Image.Save(Stream stream, ImageFormat format)
Today I was finally able to track it down to the Tiff image being created (or modified) by Adobe Photoshop and Adobe Photoshop is adding extra Property Items (meta data tags) into the image.
With the help of Bob Powell’s tool: Discovering the Property Items present in an image, I was able to see that the Adobe Photoshop Tiff images included several additional property items that were not present in other Tiff images that worked. Removing the tags from the original image prior to converting it to a Jpeg resolved the issue.
Here is a list of all of the Microsoft Windows GDI+ image property tags in numerical order.
The PropertyTagICCProfile is id 0x8773 and the other tag that I removed to resolve this issue is id 0x935C (this Property Item is not defined in the list above but it has a header in it with “Adobe Photoshop Document Data Block”). Property Items 0x02BC and 0x8649 are also not defined in the GDI+ list above and also are added by Adobe Photoshop but they did not cause any issues so I just left them (although if removing the first two do not work for you then try removing the other two also).
Here is the code that I used to remove the offending Property Items from the Tiff image before converting it to a Jpeg in order to prevent the GDI+ Parameter is not valid exception:
// Check if this is a Tiff file
if (bmp.RawFormat.Guid.Equals(ImageFormat.Tiff.Guid))
{
//loop through all of the Properties
//looking for the offending property items added by Photoshop
foreach (PropertyItem pItem in bmp.PropertyItems)
{
switch (pItem.Id)
{
//ICC Profile tag (PropertyTagICCProfile)
//Remove this tag for Tiff to be converted to Jpeg.
case 0x8773:
bmp.RemovePropertyItem(0x8773);
break;//Unknown tag added by Adobe Photoshop
//"Adobe Photoshop Document Data Block".
//Removing this tag for Tiff to be converted to Jpeg
case 0x935C:
bmp.RemovePropertyItem(0x935C);
break;default:
break;
}
}
}//convert the image to jpeg
System.IO.MemoryStream ms = new System.IO.MemoryStream();
bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
bmp.Dispose();
bmp = new Bitmap(ms); -
Amazon is offering free one-day shipping for the Kindle
I love this. Amazon is offering free one-day shipping for their Kindle starting tomorrow December 23. This means you can buy the Kindle up until midnight (EST) on December 23, 2009 and still have it delivered in time for Christmas. (There is free 2-day shipping if you buy it today.) What an awesome way to bring in new customers.
Kudos to the Amazon marketing team for coming up with this marketing idea. But I think the real credit should go to all of the Amazon people who made the free one-day shipping a reality. I am sure tons of marketing people have had the idea to use free one-day shipping right before Christmas to promote a product but have not had the behind the scenes infrastructure to actually pull it off.
Check out the count down clock on their home page too: