MakeRelative 方法
.NET Framework 类库
VirtualPathUtility..::.MakeRelative 方法

更新:2007 年 11 月

返回从一个包含根操作符(代字号 [~])的虚拟路径到另一个此类虚拟路径的相对虚拟路径。

命名空间:  System.Web
程序集:  System.Web(在 System.Web.dll 中)

Visual Basic(声明)
Public Shared Function MakeRelative ( _
    fromPath As String, _
    toPath As String _
) As String
Visual Basic (用法)
Dim fromPath As String
Dim toPath As String
Dim returnValue As String

returnValue = VirtualPathUtility.MakeRelative(fromPath, _
    toPath)
C#
public static string MakeRelative(
    string fromPath,
    string toPath
)
Visual C++
public:
static String^ MakeRelative(
    String^ fromPath, 
    String^ toPath
)
J#
public static String MakeRelative(
    String fromPath,
    String toPath
)
JScript
public static function MakeRelative(
    fromPath : String, 
    toPath : String
) : String

参数

fromPath
类型:System..::.String

要返回的相对虚拟路径的起始虚拟路径。

toPath
类型:System..::.String

要返回的相对虚拟路径的结束虚拟路径。

返回值

类型:System..::.String

fromPathtoPath 的相对虚拟路径。

异常条件
ArgumentException

fromPath 不含有根路径。

- 或 -

toPath 不含有根路径。

如果 fromPathtoPath 不含有根路径(即,该路径不等于根操作符(代字号 [~]);不以代字号 (~) 开头,如一个代字号后跟一个正斜杠 (~/) 或一个代字号后跟双反斜杠 (~\\);或者不是以正斜杠 (/) 开头),则会引发 ArgumentException 异常。

URI 中使用的查询字符串参数和 HTML 定位点不用于确定相对路径。

如果 fromPath"/directory1/file1.aspx" 并且 toPath"/directory2/file2.aspx",则 MakeRelative 方法将返回 "../directory2/file2.aspx"

Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

.NET Framework 和 .NET Compact Framework 并不是对每个平台的所有版本都提供支持。有关支持的版本的列表,请参见.NET Framework 系统要求

.NET Framework

受以下版本支持:3.5、3.0、2.0
社区内容   什么是社区内容?
添加新内容 RSS  批注
Processing
Page view tracker