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 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
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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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>...
|
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. ...
|
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>...
|
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>...
|
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...
|
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...
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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: 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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |