Solved

Obtaining 'Network Path' from Open File Dialog

Posted on 2001-07-09
7
575 Views
Last Modified: 2010-04-06
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

0
Comment
Question by:Greystoke
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
7 Comments
 
LVL 13

Expert Comment

by:Epsylon
ID: 6265502
procedure TForm1.Button1Click(Sender: TObject);
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;
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 6265522
Forgot

   StrDispose(p1);
   StrDispose(p2);


:o)
0
 
LVL 8

Expert Comment

by:TOndrej
ID: 6265615
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)
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 13

Expert Comment

by:Epsylon
ID: 6265681
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(drive), 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;
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 6265773
ExpandUNCFileName is a lot easier  :o)
0
 
LVL 1

Accepted Solution

by:
piscean earned 300 total points
ID: 6279425
Use this function ...

function GetAbsoluteFilePath(RefPath: String; var AFilePath: String): Boolean;
var
  R : PChar;
  RS : Cardinal;
begin
  {I assume that you pass the OpenDialog.Filename
  The path is complete ...}
  {You can remove the next 3 lines if you set ofFileMustExists to True and make this a procedure}
  Result := FileExists(RefPath);
  if not Result then
    Exit;
  RS := 256;
  GetMem(R, RS);
  if WNetGetConnection(PChar(Copy(RefPath, 1, 2)), R, RS) = 0 then
    begin
      System.Delete(RefPath, 1, 2);
      AFilePath := StrPas(R) + RefPath;
    end
   else
    AFilePath := RefPath;  
  R := Nil;
  FreeMem(R);
end;
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 6627574
Sure...
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question