Greystoke
asked on
Obtaining 'Network Path' from Open File Dialog
Is there any way of either forcing the user to choose a file from Network Neighbourhood, or if they specfiy a file from a mapped drive - to show the full network path.
That is, any file that a user chooses I require in the following format:
\\Machine Name\Dir1\Dir2\File.ext
That is, any file that a user chooses I require in the following format:
\\Machine Name\Dir1\Dir2\File.ext
Forgot
StrDispose(p1);
StrDispose(p2);
:o)
StrDispose(p1);
StrDispose(p2);
:o)
You could also use ExpandUNCFileName from SysUtils and check if the first two characters of the returned string are \\ (otherwise the file is a local file)
I have not fully tested it...
function UnMap(path: String): String;
var a: array[0..MAX_PATH] of Char;
drive: String;
retval : DWORD;
len : Cardinal;
begin
Result := path;
drive := ExtractFileDrive(path);
Delete(path, 1, length(drive));
len := sizeof(a);
retval := WNetGetConnection(PChar(dr ive), a, len);
if retval = 0 then
Result := a + path;
end;
procedure TForm1.Button1Click(Sender : TObject);
begin
if OpenDialog1.Execute then
Label1.Caption := UnMap(OpenDialog1.FileName )
end;
function UnMap(path: String): String;
var a: array[0..MAX_PATH] of Char;
drive: String;
retval : DWORD;
len : Cardinal;
begin
Result := path;
drive := ExtractFileDrive(path);
Delete(path, 1, length(drive));
len := sizeof(a);
retval := WNetGetConnection(PChar(dr
if retval = 0 then
Result := a + path;
end;
procedure TForm1.Button1Click(Sender
begin
if OpenDialog1.Execute then
Label1.Caption := UnMap(OpenDialog1.FileName
end;
ExpandUNCFileName is a lot easier :o)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Sure...
Var
p1, p2 : PChar;
retval : DWORD;
len : Cardinal;
begin
p1 := StrAlloc(255);
p2 := StrAlloc(255);
StrCopy(p1, 'F:');
len := 255;
retval := WNetGetConnection(p1, p2, len);
If Retval <> 0 Then ShowMessage('Error No : ' + IntToStr(retval));
ShowMessage(String(p2));
end;