473,467 Members | 1,554 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How can I get the File shortName in 8.3 format using C#

Hi,
I am porting a old application from Asp, in the old code, I am using
"Server.CreateObject("Scripting.FileSystemObject") " to get the file
short name in 8.3 format, but I am wondering if there is pure C# way to
get the file short name instead of using ActiveX object?

Thanks
-Si Jingnan
Nov 17 '05 #1
3 6521
There isn't a BCL method that I know of, but P/Invoke is probably less
clunky than doing COM interop and creating a dependency on the Scripting
library.

Add the following declaration to your code, and then call GetShortPathName()

[DllImport("kernel32.dll")]
static extern uint GetShortPathName(string lpszLongPath,
[Out] StringBuilder lpszShortPath, uint cchBuffer);

Taken from (see for sample code):
http://www.pinvoke.net/default.aspx/...tShortPathName
Joshua Flanagan
http://flimflan.com/blog
Jingnan Si wrote:
Hi,
I am porting a old application from Asp, in the old code, I am using
"Server.CreateObject("Scripting.FileSystemObject") " to get the file
short name in 8.3 format, but I am wondering if there is pure C# way to
get the file short name instead of using ActiveX object?

Thanks
-Si Jingnan

Nov 17 '05 #2
Thanks, it works, but a little bit problem, the API can only return the
short name for a exist file (not a big problem).

-Si Jingnan
Joshua Flanagan wrote:
There isn't a BCL method that I know of, but P/Invoke is probably less
clunky than doing COM interop and creating a dependency on the Scripting
library.

Add the following declaration to your code, and then call GetShortPathName()

[DllImport("kernel32.dll")]
static extern uint GetShortPathName(string lpszLongPath,
[Out] StringBuilder lpszShortPath, uint cchBuffer);

Taken from (see for sample code):
http://www.pinvoke.net/default.aspx/...tShortPathName
Joshua Flanagan
http://flimflan.com/blog
Jingnan Si wrote:
Hi,
I am porting a old application from Asp, in the old code, I am using
"Server.CreateObject("Scripting.FileSystemObject ")" to get the file
short name in 8.3 format, but I am wondering if there is pure C# way to
get the file short name instead of using ActiveX object?

Thanks
-Si Jingnan

Nov 17 '05 #3
Yes, I think that restriction is necessary.
If the Scripting.FileSystemObject gives you the shortname for a file
that does not exist, I don't see how it could be reliable.
The shortname for a file depends on the other files in the filesystem at
the the time file is created. For example, if you have a file named:
MyReallyLongFilename.txt
and create it in an empty directory, its shortname will be:
MyReal~1.txt

However, if you created that same file in a directory that already
contained a file named:
MyReallyGoodNovel.txt
your file would be named
MyReal~2.txt

Two different possible shortnames for the exact same filename. It
depends on the other files in the folder.
Jingnan Si wrote:
Thanks, it works, but a little bit problem, the API can only return the
short name for a exist file (not a big problem).

-Si Jingnan
Joshua Flanagan wrote:
There isn't a BCL method that I know of, but P/Invoke is probably less
clunky than doing COM interop and creating a dependency on the Scripting
library.

Add the following declaration to your code, and then call GetShortPathName()

[DllImport("kernel32.dll")]
static extern uint GetShortPathName(string lpszLongPath,
[Out] StringBuilder lpszShortPath, uint cchBuffer);

Taken from (see for sample code):
http://www.pinvoke.net/default.aspx/...tShortPathName
Joshua Flanagan
http://flimflan.com/blog
Jingnan Si wrote:

Hi,
I am porting a old application from Asp, in the old code, I am using
"Server.CreateObject("Scripting.FileSystemObjec t")" to get the file
short name in 8.3 format, but I am wondering if there is pure C# way to
get the file short name instead of using ActiveX object?

Thanks
-Si Jingnan

Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: bart plessers | last post by:
Hello, I am developping a file browser bu use of internet explorer. I am already so far that I get a full list of all the files of a selected directory. However, I only want to display...
1
by: Eric Cory | last post by:
Hello Gurus I can't get Dart PowerFTP to do anything. I create the ftp oblect and set the connection values, but when I do a get, put or even an invoke for a site command, I always get the...
5
by: dm1608 | last post by:
I would like to plug in a bunch of static, but related, information into a XML file that can be used by my VB.NET 2005 utility application. I would like to do something like: <shortname>...
9
by: JimmyKoolPantz | last post by:
IDE: Visual Studio 2005 Language: VB.NET Fox Pro Driver Version: 9.0.0.3504 Problem: I currently have a problem altering a DBF file. I do not get any syntax errors when running the program. ...
6
by: saif.shakeel | last post by:
Hi, I need to replace a string in xml file with something else.Ex - <SERVICEPARAMETER id="_775" Semantics="subfunction" DDORef="_54"> <SHORTNAME>rate</SHORTNAME> <LONGNAME>rate</LONGNAME>...
7
by: saif.shakeel | last post by:
Hi, I need to replace a string in xml file with something else.Ex - <SERVICEPARAMETER id="_775" Semantics="subfunction" DDORef="_54"> <SHORTNAME>rate</SHORTNAME> <LONGNAME>rate</LONGNAME>...
2
butro
by: butro | last post by:
I have a form which can check whether is an image or not. But when i try to choose a real image whose name include more than one "." character, the script fails. The split function can not be detect...
2
by: pmlane2001 | last post by:
I have a PHP SOAP XML file size problem that I was wondering if anyone has seen before. I have an XML file that when I put it through my PHP script with 270 lines (13,082 KB) it works fine. If I...
1
by: =?Utf-8?B?RVFOaXNo?= | last post by:
Not sure if this is the spot to ask but I need some help with a script I hijacked and put to my own use in an .ASP page any ways I am using the FilesystemObjects to get a directory and file...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.