Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Relative path to wwwroot for C++ Builder
#1
I am using C++ Builder 10.2.3 with Intraweb 15.6.1

I am trying to access a subfolder (myfolder) I created in wwwroot following this reference article:

https://docs.atozed.com/docs.dll/develop...20XIV.html

This for sure does not work as a relative path in C++ builder: "\\myfolder\\myfile.xml"
It is referring to C:\myfoler\myfile.xml

This one is close: "myfolder\\myfile.xml". But is referring to the application path were the .exe is running!

So, in C++ Builder, how can I use a relative path to access a file or subfolder located in wwwroot?
Reply
#2
(06-05-2024, 03:24 PM)valmeras Wrote: I am using C++ Builder 10.2.3 with Intraweb 15.6.1

I am trying to access a subfolder (myfolder) I created in wwwroot following this reference article:

https://docs.atozed.com/docs.dll/develop...20XIV.html

This for sure does not work as a relative path in C++ builder: "\\myfolder\\myfile.xml"
It is referring to C:\myfoler\myfile.xml

This one is close: "myfolder\\myfile.xml". But is referring to the application path were the .exe is running!

So, in C++ Builder, how can I use a relative path to access a file or subfolder located in wwwroot?

maybe its a bug in 15.6.1 ?
I use subfolder to store image files.
the absolut path is iE: p:\myproject\debug\wwwroot\img
and I use only "img" to read or write.

I use C-Builder 10.2.3 too, but  IW 15.5.9.
Reply
#3
I don't know what image [b]joergb [/b]is loading.
But I tried Intraweb 15.5.9 and the issue is the same.

It works only with TIWImageFile->ImageFile->Filename.

For all others like TIWImage->Picture->LoadFromFile and IWMemo->LoadFromFile and TStringLits->LoadFromFile, it does not work!
It is exactly as I explained before. It is looking for the folder at the .exe location.

So, is that Intraweb normal functioning?
Reply
#4
>>I am trying to access a subfolder (myfolder)
>>I created in wwwroot following this reference article:

If I read the article correctly it looks to explain absolute and relative paths in terms of serving content via the web server.


>>This for sure does not work as a relative path
>>in C++ builder: "\\myfolder\\myfile.xml" It is
>>referring to C:\myfoler\myfile.xml

This would refer to accessing your files internally from a Windows executable.  To use relative paths in this case you would need to know your current directory which generally defaults to the application path.  This can change if run from a short cut, run as a service, or changed in code.

>>This one is close: "myfolder\\myfile.xml". But
>>is referring to the application path were the
>>.exe is running!

This looks correct to me based on the above.


I use something like gGetAppPath()+"wwwroot\\myfoler\\myfile.xml" for file paths in case the current directory isn't set to the application folder.
Reply
#5
Yes. This is exactly what I am trying to do: save and retrieve some files from wwwroot. This is exactly what it is supposed to be.

And yes, I am using a stand alone application.

I know how to access it using the full directory link: IWServerController()->ContentPath
This will give you direct access to the contents in the wwwroot as explained in the article.

The interest of this question is to be able to use a relative path.

I know that I am not paying for priority support. But at least Alexandre from Atozed can answer to this question to tell if it is a bug or the normal functioning?
Reply
#6
As MJS pointed out, the article explains how relative and absolute URL paths are resolved when serving content from the IntraWeb server, not how to access a particular file using the OS file system.

The short answer is: You cannot safely use a relative path to access a file on your hard disk. Always use the full path to the file.

The longer answer is:  In the Windows file system, a relative path is always defined relative to the current working directory. However, the current working directory cannot be safely determined in a multi-threaded application because any thread could possibly change it.
In Windows, the current directory is a property of the process, not of individual threads. This means that if one thread changes the current directory, it affects all threads within the same process.
IntraWeb itself won't change the current working directory but many 3rd party frameworks do.
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)