473,396 Members | 1,676 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

AbsolutePath<-> relative path

Is there something already done to get absolute path from relative path, and
relative path from absolute path:
Example:
BasePath="c:\a\b\c"
RelativePath="..\e\f\g\..\m"
AbsolutePath=FindAbsolutePath(BasePath, RelativePath)

and the same in other direction
Nov 21 '05 #1
4 9697
>AbsolutePath=FindAbsolutePath(BasePath, RelativePath)

AbsolutePath = Path.GetFullPath(Path.Combine(BasePath, RelativePath))

and the same in other direction


Nothing in the BCL but there's the native API PathRelativePathTo.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 21 '05 #2
> Nothing in the BCL but there's the native API PathRelativePathTo.

How do I use it from VB.NET?

Nov 21 '05 #3
Nothing in the BCL but there's the native API PathRelativePathTo.


How do I use it from VB.NET?


Declare Auto Function PathRelativePathTo Lib "shlwapi.dll" (ByVal
pszPath As StringBuilder, ByVal pszFrom As String, ByVal dwAttrFrom As
Integer, ByVal pszTo As String, ByVal dwAttrTo As Integer) As Boolean

....

Const FILE_ATTRIBUTE_DIRECTORY As Integer = &H10
Dim relativePath As New StringBuilder(260)
PathRelativePathTo(relativePath, "C:\Windows\System32",
FILE_ATTRIBUTE_DIRECTORY, "C:\Program Files\Microsoft Visual Studio
..NET 2003", FILE_ATTRIBUTE_DIRECTORY)
Console.WriteLine(relativePath)

' Prints ..\..\Program Files\Microsoft Visual Studio .NET 2003

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 21 '05 #4
Thank you. I deceided to implement my own .NET classs for that
(absolute2relative and relative2absolute ). Took half a day but now I have
just what I wanted :).

"Mattias Sjögren" <ma********************@mvps.org> schrieb im Newsbeitrag
news:%2***************@TK2MSFTNGP09.phx.gbl...
Nothing in the BCL but there's the native API PathRelativePathTo.


How do I use it from VB.NET?


Declare Auto Function PathRelativePathTo Lib "shlwapi.dll" (ByVal
pszPath As StringBuilder, ByVal pszFrom As String, ByVal dwAttrFrom As
Integer, ByVal pszTo As String, ByVal dwAttrTo As Integer) As Boolean

...

Const FILE_ATTRIBUTE_DIRECTORY As Integer = &H10
Dim relativePath As New StringBuilder(260)
PathRelativePathTo(relativePath, "C:\Windows\System32",
FILE_ATTRIBUTE_DIRECTORY, "C:\Program Files\Microsoft Visual Studio
.NET 2003", FILE_ATTRIBUTE_DIRECTORY)
Console.WriteLine(relativePath)

' Prints ..\..\Program Files\Microsoft Visual Studio .NET 2003

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Nov 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Richard | last post by:
We are distributing a VS2003 solution to our customers that includes a .NET assembly (dll file) and a sample project for how to use the dll. The customer can then customize the sample or add a new...
7
by: Rizaan Jappie | last post by:
is it possible to get the relative path based on a absolute path in c#? *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it!
8
by: dw | last post by:
Hello, all. I have a site that I'm testing on my LOCALHOST and also on a remote server, depending on whether I'm at work or at home. I don't want the OLEDBDATAAdapter to be pointing to the remote...
6
by: openleren | last post by:
Hi all, how can I use a relative path in my web.config file for an Access db?: Instead of using <configuration> <appSettings> <add key="conAccess" value="microsoft.jet.oledb.4.0;data...
4
by: Win, Pats | last post by:
I have a snippet of HTML that I inject into a number of pages throughout my Web site at runtime. My problem is that I'm not getting the image to appear in all documents into which this snippet is...
2
by: Jordan Richard | last post by:
Put another way, is there any way I can tell ASP.NET to convert a path (imbedded in a string variable, "~/images/some_image.gif") to a root-relative path, that the client will understand, for the...
8
by: ghadley_00 | last post by:
Hi, I have an access database with a table linked to an external text file. Occasionally the location of the database and the text file change (but are always in the same directory). Is there a...
3
by: bobdydd | last post by:
Hi Everybody Access 2000, Outlook 2000 Windows XP I am running the code below to open Microsoft Outlook from a Command Button. It works fine until I tried it on a machine that has Office...
2
by: BD | last post by:
Hi there. Using 8.2 on Windows. I have a situation where I have a db backup, which I want to deploy to a group of developer workstations. The target directory for the database files will be...
6
by: teja1234 | last post by:
Hi All, I am using absolute path in my macro code, but i want to change it to relative path. I am not sure what exactly relative path will do how to use relative path in macro. Please can any one...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.