Wednesday, June 27, 2012

File Upload or Browse, Filepath or Filename Too Long

This is good to keep in mind if you develop applications or websites:

Websites or applications can safely handle 250 chars maximum for filepath + filename (sometimes less than 259, so 250 to be safe) when browsing to a file. I keep this in mind as a general rule of thumb, and it has helped me save some time when diagnosing problems with a webpage or an application.

Sometimes when a user is trying to browse to and upload a file on a webpage or application where the filepath + filename of the file is too long, it will produce an error or just fail silently. Either way, the user will not be able to upload their file. If providing support for this issue, I will usually ask them to provide the full filepath + filename for the file they are having trouble uploading, as well as send the file in an attachment. This lets me see if the filepath + filename exceeds 250 chars. This also gives me a chance to check out the file and see if there is a lock on it.

When an application has trouble accessing a file, a lock will often be imposed on it. In this situation, you will be unable to edit, rename, copy, or delete the file as you normally would through Windows. Either of these commands can only be accomplished through command-line, or with the PathTooLong utility explained below. In the case of providing support to a user where I do not have direct access to their machine, I will usually ask if they have the file(s) backed up.

Another non-user-related issue is when an application programatically crawls a folder or browses to a file where a filepath + filename is too long. Usually, this will produce an error that says something along the lines of, "filepath too long". Sometimes we are not talking about just one file, but many files where the filepath is too long. This error can be difficult to diagnose because it may only tell you about one file at a time as you fix them one by one, and at the same time the application may have just put a lock on all files it had trouble with.

In that situation, if you have access to the machine where the problem lies and want to know which file(s) are causing the issue, there is a great utility that can help. The trial version of the PathTooLong utility can quickly scan a directory and list off all paths that are too long. The full version lets you delete or copy files that it finds, and lets you do this even when an application has put a lock on the file. It is also possible for you to accomplish delete or copy of locked files through Windows command-line.

As a final note: You may be aware that Windows NTFS or Mac file systems allows for a much higher max number of chars in filepaths + filename, and that the max char limit can be separate for both filepath and filename. These facts do not really apply to most software or websites running on IIS because they operate on the older Windows file system technology. There are a couple of workarounds to this issue as far as application development goes but, I am not convinced that they work everywhere or are future-proof.

Again, as a general rule of thumb I just assume the 250 char max rule for all filepath + filename related issues. This makes it possible to provide a solution that works for every scenario.

1 comment:

  1. If your file path is too long then you can try long path tool. It is really a nice tool.

    ReplyDelete