General discussion

Locked

scope of getcurrentdirectory

By LadyReader ·
My VB.net program reads in some constant data from a text file. I navigate to this file by setting a relative path, which I intended to wrok both on my pc, with my file structure, and in prod :

Dim path As String = Directory.GetCurrentDirectory
Dim parent As System.IO.DirectoryInfo = Directory.GetParent(path)

Dim FOLDER_PATH As String = parent.ToString & ConfigurationSettings.AppSettings("PrefixAndSuffixFilePath")

The config file entry points to the file name.
This works fine on my pc from the IDE but when I trigger the executable from a cmd file on the prod server it fails to find the required file.

Research showed that in prod path = C:\Windows and Parent = C

Obviously getcurrentdirectory is acting differently in the prod environment. Can anyone tell me what's going on or suggest an alternate method of providing a relative path? I would prefer not to hardcode the path to the text file.

Thanks!

This conversation is currently closed to new comments.

4 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

by lowlands In reply to scope of getcurrentdirect ...

Some probably silly suggestions/questions:
Does prod have same .NET runtime as your workstation (CE .NET does not support getcurrentdirectory).

Is the config file in the right location?

Do you run the file from the same location on your workstation as in prod.

can you create a small test exe. Just one button and three labels showing you the value for path, parent and current_folder

Collapse -

by LadyReader In reply to scope of getcurrentdirect ...

Thanks for your suggestions. I figured it out: when I ran the cmd file I was receiving the following error message:

"CMD.EXE was started with the above path as the current directory.
UNC paths are not supported. Defaulting to Windows directory."

which I saw but ignored. I added a PUSHD command referencing the file path I needed for my executable and let the progrma generate a relative file path based on that. This technique worked but now I am getting a Type Initializer security error.

Thanks again for trying to help.

Collapse -

by LadyReader In reply to scope of getcurrentdirect ...

Thanks for your suggestions. I figured it out: when I ran the cmd file I was receiving the following error message:

"CMD.EXE was started with the above path as the current directory.
UNC paths are not supported. Defaulting to Windows directory."

which I saw but ignored. I added a PUSHD command referencing the file path I needed for my executable and let the progrma generate a relative file path based on that. This technique worked but now I am getting a Type Initializer security error.

Thanks again for trying to help.

Collapse -

by 3xp3rt In reply to scope of getcurrentdirect ...

I don?t work with VB.net , I use Delphi, but I know there are many thinks what work similar. This kind of problem I resolve in Delphi whit the following command:
?ExtractFilePath(Application.ExeName)? This can be the basic path, from there I can give any command to find or use a file.

Back to Web Development Forum
4 total posts (Page 1 of 1)  

Related Discussions

Related Forums