Thursday, April 16, 2009

Outlook attachment error, can't create file

If you're one of those users who is notorious for opening all attachments without downloading and saving them first, you may have run into this problem before. Eventually you may get an error when trying to do so, which says:

Can't create file: yourfile.ext. Right-click the folder you want to create the file in, and then click properties on the shortcut menu to check your permissions for the folder

This can be very annoying, especially since you will most likely experience it with only a select few of your files. However, the good news is that it's not a big deal and is easily fixable.

The problem is that every time you open an attachment without saving it first, Outlook will first download it into a temporary folder and then open it from there. Unless you keep up on cleaning this temp folder, the files eventually build up. Each time you open a file with a name that already exists in this temp folder, Outlook with append a number to the name (e.g. "file.txt" opened a 2nd time would be saved in the temp folder as "file (2).txt"). This is where the problem comes in. Outlook is limited to 100 versions of the same file, so once your file name reaches "file (99).txt" (starts numbering at 0), the next one will fail to open and you'll get the error above. The fix is to go to the temp folder and clear the other copies of the same file, or if you want to be really good, empty the folder completely.

In order to clean out the temp folder, you'll first have to know where it is stored. This is really the only tricky part because it can vary from machine to machine. However, the location is stored in the system registry so you can retrieve it from there. Here's how to do this for Outlook 2003

1. Go to Start->Run, type "regedit", then press Enter. This will bring up the registry editor tool. Be careful not to make any changes to the registry as they can have adverse affects on your computer.
2. Navigate to HKEY_CURRENT_USER->Software->Microsoft->Office->11.0->Outlook->Security registry key
3. Look for the OutlookSecureTempFolder value. This is the folder location you'll need. It's easiest to double-click on it, then copy the path of the folder
4. Close Registry Editor
5. Go to Start->Run, then paste the folder path in the box and press Enter
6. The folder should pop up in Windows Explorer. This is where you'll want to delete the files from
7. Now that the files are deleted you can close that folder and try opening your attachment again

The easiest way to avoid this would be to first save your attachment to a location you're aware of, and then open it from there. Since 90+% of you will probably never do that, this will at least allow you to continue opening attachments

I haven't run into this problem with Outlook 2007, but that doesn't mean it doesn't exist. If you're having the issue with Outlook 2007, just replace the key in step #2 with HKEY_CURRENT_USER->Software->Microsoft->Office->12.0->Outlook->Security. That is where Outlook 2007 specifies its value for the temp folder

The original post that helped me figure this out can be found here.

Tuesday, April 14, 2009

Applescript to automatically replace characters in filename

Here's the second half to my post regarding automatically adding file extensions to files in OS X.

If you're in a mixed environment where Mac and PC users are, you know that it can sometimes be a challenge to get everyone to name files so that they are compatible with both types of computers. Normally the Mac users are the culprits because Macs allow a wider range of characters in the filenames. Configuring folder actions, and using a simple Applescript, you can automatically remove any characters you want from the file names though, or replace them with a different character of your choosing. Here's the Applescript:


--set the list of characters you want to replace
--disallowedChars will be replaced with the replacementChar
--in this case, an underscore
property disallowedChars : ":;,/|!@#$%^&*()+" 

--anything in disallowedChars2 will be removed altogether
property disallowedChars2 : "'"

--set the character you'd like to use to replace the invalid 
--characters specified in disallowedChars
property replacementCharacter : "_"

on adding folder items to this_folder after receiving added_items

tell application "Finder"
try
repeat with x in added_items

set fileNamed to name of x
set newName to my CleanName(fileNamed)
set (name of x) to newName

end repeat
on error
display dialog "An error occurred."
end try
end tell

end adding folder items to

--function for cleaning the characters from the file name
on CleanName(theName)

set newName to ""
repeat with i from 1 to length of theName

--check if the character is in disallowedChars
--replace it with the replacementCharacter if it is
if ((character i of theName) is in disallowedChars) then
set newName to newName & replacementCharacter

--check if the character is in disallowedChars2
--remove it completely if it is
else if ((character i of theName) is in disallowedChars2) then
set newName to newName & ""

--if the character is not in either disallowedChars or
--disallowedChars2, keep it in the file name
else
set newName to newName & character i of theName

end if
end repeat

return newName
end CleanName

Using that script in combination with OS X folder actions will allow you to successfully replace any character you want with any character you specify. The only things you'd need to modify are the disallowedChars, disallowedChars2, and replacementCharacter variables. 

Add empty item to databound drop down list in C# .NET

Do you have a data-bound drop down list, but want to leave the list empty or blank initially? Well, you can, and it's really simple. In your aspx page, where you declare your DropDownList, just make sure to do it as follows:

<asp:DropDownList ID="yourID" runat="server" AppendDataBoundItems="True">
<asp:ListItem Value="" Text="" />
</asp:DropDownList>


The key here is the AppendDataBoundItems="True" property. This allows you to define your own list items, and then any items that are bound to data are added after those items, aka appended.

You can find the original post at http://stackoverflow.com

However, if you find that you're getting the same items added multiple times you can do it this way instead. Leave AppendDataBoundItems="False" and rather add the empty/blank entry programmatically. To do that add the following code after your drop-down has been filled

DropDownList1.Items.Insert(0, new ListItem(String.Empty, String.Empty));
DropDownList1.SelectedIndex = 0;

This will add an empty/blank entry at index zero of your dropdown box, and also make sure that it is the selected value. If you don't want to change it to the selected value don't use the second line. I found this on http://stackoverflow.com as well

Monday, April 13, 2009

Embed or un-embed a linked file in an Illustrator CS3 document

The trick here is paying attention to the options in the Link screen. The symbol for showing that a file is embedded is , which will show up next to the file in the Link panel. If that symbol is not there, then the linked file is just that, linked only.

To embed the file, simply clear the Link checkbox at the bottom left of the window when you select the file to be linked. That will embed it rather than create a link. 

If you want to link a file rather than embed it, make sure the Link checkbox is checked when you place the file into your document. If you've already embedded it, you can go back in and check that box to change it to being linked.

Just watch for the "embedded" image, or lack of, to keep track of the status of your placed document. There's an Adobe article on how to do this same thing, and it can be found here.

Thursday, April 9, 2009

Send email via command line with sendmail

So you want to make sure sendmail is running and able to send email messages, but can't quite figure out the command to test it from the command line? It's easier than you may think, but it requires you to create an input file to specify the parameters.

Create a new file, we'll call it email.txt, with vi or whatever text editor you use. Then add parameters for the SMTP headers that you want to include in the message, such as "From:", "To:", and "Subject:". You also MUST remember to leave an extra, empty line at the end of the document because that signals the end of your email message. An example of the text for a basic message would be:

From:me@myemail.com
To:you@youremail.com
Subject:Hello, thanks for reading

Hi, I appreciate you reading this blog post.



You can specify other header parameters in the file as well, such as date, cc, etc by simply adding an entry for them. If you want to find out more, check the SMTP Wiki, or perform your own Google search to find resources.

After you've saved that text into your email.txt file, now you're ready to use sendmail to send this message. You can use the -t switch to import your file.

/usr/sbin/sendmail -t < email.txt

That is assuming you're still in the same directory as your email.txt file. If not, you'll want to specify the full path to the email.txt file so sendmail knows what to import.

If you're looking for more information, check out the original post I used to answer my question about sendmail.

Tuesday, April 7, 2009

Windows update problems with Vista service pack 1, error 80070026

I tried helping someone out who was having issues installing Vista SP1 on her laptop (Vista Home Premium). I had heard stories of problems, but haven't had any myself on the machines I've installed it on many computers already so I thought it would be pretty easy to take care of. Wrong! I had to deal with Microsoft support, which is providing free support for this problem until June 30th, 2009. If you want to jump right to that, you can go to http://support.microsoft.com/oas/default.aspx?prid=11274&gprid=500921. Anyway, on to the issue...

Upon attempting to install Vista's service pack 1, I kept getting an error code of 80070026. After guessing Conficker, then other spyware, and just about everything else, I took a step back. I popped the hard drive out of the laptop and into my desktop so I could run a chkdsk /r, and also another virus scan. Neither helped, so I turned to the free support option. 

The support agent guessed a corrupt .NET Framework installation, but after cleaning the .NET installations with a handy tool from www.pcsafety.us, we tried installing the latest version only to encounter another error. This is when the agent suggested using the in-place upgrade feature of Vista. I hadn't heard of this before, and was pleasantly surprised.

The in-place upgrade will reinstall your system files, but leave your files and applications intact. Yes, I was skeptical too, but I ended up having no issues with it. I still suggest backing up any files you want to save prior to doing anything with your operating system though.

The first thing I had to do was disable my startup programs and services. You can do this by going to Start->Run, then typing in "msconfig" and pressing Enter. If you don't have the Run option, you can either add it by customizing you Start menu, or go to the command prompt (Start->All Programs->Accessories->Command Prompt) and enter "msconfig" there instead. This will bring up the Microsoft system configuration utility. Go to the Services tab, check the box to Hide all Microsoft Services, then click on Disable All. Then go to the Startup tab and click on Disable All. Now click Apply, then OK. You will be prompted to restart, which is fine. Go ahead and restart the computer. After the upgrade, you will need to go back into the msconfig tool to reenable these services and programs.

After restarting, put in the Vista installation CD/DVD. One thing to note is that you MUST use installation media containing the same version of Vista that you already have installed. As an example, in my case the laptop had Vista Home Premium, so I had to use a Vista Home Premium install disc. Mismatched versions will not give you the upgrade option. Once the disc is inserted, start the Vista installation procedure if it doesn't start automatically. Here you'll see two options, one of which is upgrade. It will explain that the upgrade will not harm your files or applications, but only reinstall the Windows system files. Follow that path. The rest is pretty simple, and mainly is just a matter of clicking Next or Continue. However, the in-place upgrade will wipe out any updates installed prior to it, so once the upgrade has completed, make sure to run Windows Updates until you have all of the latest patches installed. I had to go through Windows Update a few times before it had everything, but it didn't give me any issues this time around. Service pack 1 was installated without any problems either. The only thing left after this is to go back into "msconfig" and reenable your Startup programs, and your Services. After you've done that, restart, and the pain of not being to update your Vista machine should be gone.

Monday, April 6, 2009

C# ASP .NET fileupload control problems in Firefox and Safari on OS X

I'm working on providing a web form for input to a department that needs it, but have been running into problems getting the Visual Studio .NET 2005 C# FileUpload control to work with both Firefox and Safari on Mac OS X. I've had no issues with any browsers on the Windows machine: IE, Firefox, Safari, and Chrome. I've narrowed it down to a few things.

First, Safari 3.2.1 works. Most of the OS X users who were using Safari haven't updated their systems. I've found that the page errors disappear as soon as the latest version of Safari is installed. That's a logical first step when trying to diagnose the problem, but I wanted to state it because of what I found with Firefox...

The latest version of Firefox, Firefox 3.0.8, does NOT work on OS X with the fileupload control. However, Firefox 3.0.6 does seem to work (haven't tested 3.0.7), and Firefox 3.0.8 on Windows works fine as well.

Again, I'm using the built-in FileUpload control for C# web forms on my pages, from within the Visual Studios .NET 2005 environment. Maybe I'm the only one experiencing this, but since the odds are usually against that, I wanted to post this and also give you the workarounds I've found to this point in case you're running into the same issue. If I figure anything else out regarding the FileUpload control in OS X browsers, I'll post an update.

Update: Still no success when trying it with Firefox 3.1 beta 3. There is a Google discussion for this, which can be found here: http://groups.google.com/group/mozilla.feedback.firefox.prerelease/browse_thread/thread/16c5480e8d620842

Friday, April 3, 2009

Create a reusable selection list for ntbackup

ntbackup is a free Microsoft utility for backing up or restoring files from your Windows server or desktop. You can download it from Microsoft here, but odds are it's already installed on your machine.

One nice feature of ntbackup is that you can save a list of what you'd like to backup, called a backup selection list, and then use that one list for multiple backup jobs. It's really easy to do to. Here's how:

1. Go to Start->All Programs->Accessories->System Tools->Backup. It'll likely start in wizard mode, so if it does, just click on the link for Advanced Mode.
2. Click on the Backup tab
3. You'll see a file selection tool. Use this to select everything you want to backup.
4. Once everything that you want to backup is selected, go to Job->Save Selections As... and save your .bks file wherever you want it
5. Go ahead and close ntbackup

Now you have a selection file that can be used to set up multiple backup jobs. It can help save time if you have to manage multiple jobs, and is useful if you want to use ntbackup from the command line. ntbackup from the command line is talked about in MS KB 814583. If you're looking to add email notification to your ntbackup job, check out this post from just a few minutes earlier.

Adding email notifications to ntbackup

ntbackup is the free, Windows-based, backup utility provided by Microsoft. It is a very helpful tool for backing up and restoring files on a Windows computer. You can download it for free from Microsoft.com if you don't have it, but unless your computer is older, it should be included in your original Windows installation. This article focuses mainly on Windows Server 2003 and Windows XP.

One of the features missing in ntbackup is email notifications. Maybe you don't need them, but I would guess that like myself, you want to at least know whether your backup job finished. There's a way to get around this though, and that is by scripting. You can use ntbackup from the command line, and then add an additional command to use a simple smtp mail program to send an email. This actually isn't all that difficult, as long as you already have an SMTP host you're allowed to send mail through. Here's how:

First you need to create a batch file. You can use VB Script if you'd like, but I think batch files are easier to work with for more people. The reason for using a script file is because you can use it to perform multiple commands, and also can schedule it to run using Windows scheduler. You can create this file simply by creating a new text document in Notepad, then using File->Save As to save it as a .bat file. You'll have to change the Save As Type to All Files in order for this to work, otherwise Notepad will assign the default .txt extension to your file. For now that's all you need to do, as you'll add the commands to the file later in the next steps.

Now you need to know how to run ntbackup from the command line. A good reference for this is MS KB 814583. The main thing to know here is that you can select what to backup two different ways: in the command itself, or with a saved backup selection file (.bks). I suggest using the backup selection file, since you can use the ntbackup GUI to create it. To do this, check out my other post about saving a selection list for ntbackup.

For an example, lets say I want to back up the entire Documents and Settings folder to a location on a drive mapped as Z, and created a .bks file with that information in it called BackupDocs.bks. I saved my .bks file right on the C drive, so it's at "C:\BackupDocs.bks".  I can use the command line to invoke the backup by using the command:

ntbackup backup "@C:\BackupDocs.bks" /J "BackupJobName" /F "Z:\BackupFolder\BackupFile.bkf"

In the example, /J assigns a name to the backup job, and /F lets you specify a file location for your backup file. Consult KB 814583 if you want to find out more about ntbackup from the command line and the various switches you can use.

Ok, now that you know how to use ntbackup from the command line you're ready to create your .bat file. You can either go into Notepad and open it from there, or right-click on it and choose Edit. Either way it'll open in Notepad. On the first line, add you ntbackup command and save. Now if you were to double-click on your .bat file, it would execute that command. You can add multiple ntbackup commands if you'd like, or any other command line commands you'd like to perform before or after the backup. One command you're going to want to add to the end is for your email, and you'll have to use a command line SMTP program.

If you just want a notification saying the job completed, a free SMTP program you could use is called bmail. It's free to download, and does the job. Clicking that link will bring you to a download page, and also contains more information on the command line switches you'll need in order to get it to work. If you want to include the backup log files in the email, you'll have to do some searching to find a command line utility for that. I ended up writing my own C#-based Windows application just for my purposes. If you're interested in that rather than finding one somewhere else, leave me a comment and I can get it to you. Once you've added your SMTP notification command to the end of your batch file, you can save and close. The only thing left is to use Windows scheduler to schedule your batch file to run.

You can find the Windows scheduler by going to Start->All Programs->Accessories->System Tools->Scheduled Tasks. When asked what you want to schedule, use the Browse button to go out and select your .bat batch file that you created above. This way your backup and notification will run according to whatever schedule you set.

That's it. This turned into a longer post than I originally intended, but hopefully it covers the topic enough to help you get those notification going. If you run into problems, or have more questions, leave me a comment.

Wednesday, April 1, 2009

Use cascading style sheets (css) with your webpage

I'm going to assume you're familiar with the different properties you can set using css. If not, check out the tuturial here. There are a few different ways you can include cascading style sheets (css) on a webpage.

1. Inline
2. With the <style> tag
3. Using an external stylesheet

Inline

You can simply set the style property for various HTML tags. This works best if the css property you are defining is unique to that particular tag. If it is not unique, you will be better off using one of the other two options

<div style="position:absolute; color:red; width:100%; top:50px; ></div>

Using the <style> tag

You can use <style> to define css properties for an entire page. This helps to keep you from having to define the same properties over and over, and makes changes much easier. However, if the properties carry over from page to page, you most likely will want to use the next option of external stylesheets. The text below does the same thing as the inline example, except it will affect all <div> tags on the webpage this is defined in.

<head>
<style type="text/css">
div { position:absolute; 
color:red; 
width:100%; 
top:50px; }
</style>
</head>

Including an external stylesheet (.css file)

If you have a styles that need to span multiple pages on your site, the best way to do that is with an external file that contains all of the defined styles needed. You can then link that file to any of your pages using a simple tag in the section, which will allow you to use the css properties within that file in any of those pages. This helps consolidate your properties to a single location so you can make site-wide changes by modifying a single line. This example assumes you have a file containing you css properties already, it's at the root of your site, and it's named myCSS.css.

<head>
<link rel="stylesheet" type="text/css" href="myCSS.css" />
</head>


It's relatively simple, and can make modifying your pages much, much easier later on. You should understand css inheritance as well. It's a top-down approach, and the style most closely defined to any particular element is the one that takes precedence.  This means you can override a css property defined in a linked stylesheet, or in a <style> tag, by using an inline style. If you want to find out more about css inheritance, I suggest checking out http://www.webdesignfromscratch.com/css-inheritance-cascade.php