尝试此代码,写入
Delphi .NET
你必须把它翻译成C#
function WNetGetUniversalName; external;
[SuppressUnmanagedCodeSecurity, DllImport(mpr, CharSet = CharSet.Ansi, SetLastError = True, EntryPoint = 'WNetGetUniversalNameA')]
function ExpandUNCFileName(const FileName: string): string;
function GetUniversalName(const FileName: string): string;
const
UNIVERSAL_NAME_INFO_LEVEL = 1;
var
Buffer: IntPtr;
BufSize: DWORD;
begin
Result := FileName;
BufSize := 1024;
Buffer := Marshal.AllocHGlobal(BufSize);
try
if WNetGetUniversalName(FileName, UNIVERSAL_NAME_INFO_LEVEL,
Buffer, BufSize) <> NO_ERROR then Exit;
Result := TUniversalNameInfo(Marshal.PtrToStructure(Buffer,
TypeOf(TUniversalNameInfo))).lpUniversalName;
finally
Marshal.FreeHGlobal(Buffer);
end;
end;
begin
Result :=System.IO.Path.GetFullPath(FileName);
if (Length(Result) >= 3) and (Result[2] = ':') and (Upcase(Result[1]) >= 'A')
and (Upcase(Result[1]) <= 'Z') then
Result := GetUniversalName(Result);
end;
再见。