473,396 Members | 1,871 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 6517
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...

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.