Question Converting Long File Path to Short Path (Network Location)

APlusInnovations

New member
Joined
Dec 13, 2010
Messages
1
Programming Experience
Beginner
Hello,

I have been looking for a solution to my problem for the past week. Hopefully someone here can help me out.

I use an old executable that converts a certain file type to another. The Windows interface that comes with it is cumbersome, so I am making a right-click option to speed things up. I added a right-click option that points to the visual basic executable that I am working on followed by "%1". This feeds the path and name of the file that was right-clicked to my visual basic program as an argument. The only problem is, the old executable that actually does the converting doesn't work with long file paths. So I have to convert the long file path to a short one in my code.

I found a bit of code that worked in my testing, but doesn't work in the real world. If I right-click on a file that is anywhere on my hard drive, everything works great. It does exactly what I want it to. In actual use, however, the files being converted are on a file server. When I use my program to convert a file, it stops and gives me an error when it gets to the code that converts the long path to a short one. I've tried browsing to the files through the mapped drive and through the network name (\\servername).

Here is the code I came across in my search and have been testing:

VB.NET:
Private Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal longPath As String, ByVal shortPath As String, ByVal shortBufferSize As Int32) As Int32

As I said, it works for local files, but does not for a network location. If there is not a way to do it in code, I would be willing to use some sort of work around that would feed a short path to my program to begin with. I am using Visual Basic 2010 Express on Windows XP. Any help would be greatly appreciated.

Thanks!
 
Back
Top