共用方式為


VirtualPathUtility.IsAppRelative(String) 方法

定義

傳回布爾值,指出指定的虛擬路徑是否相對於應用程式。

public:
 static bool IsAppRelative(System::String ^ virtualPath);
public static bool IsAppRelative (string virtualPath);
static member IsAppRelative : string -> bool
Public Shared Function IsAppRelative (virtualPath As String) As Boolean

參數

virtualPath
String

要檢查的虛擬路徑。

傳回

如果 virtualPath 相對於應用程式,true;否則,false

例外狀況

virtualPath null

範例

下列程式代碼範例示範如何使用 IsAbsoluteIsAppRelativeToAppRelative 方法。

StringBuilder sb2 = new StringBuilder();
String pathstring1 = Context.Request.CurrentExecutionFilePath.ToString();
sb2.Append("Current Executing File Path = " + pathstring1.ToString() + "<br />");
sb2.Append("Is Absolute = " + VirtualPathUtility.IsAbsolute(pathstring1).ToString() + "<br />");
sb2.Append("Is AppRelative = " + VirtualPathUtility.IsAppRelative(pathstring1).ToString() + "<br />");
sb2.Append("Make AppRelative = " + VirtualPathUtility.ToAppRelative(pathstring1).ToString() + "<br />");
Response.Write(sb2.ToString());
Dim sb2 As New StringBuilder()
Dim pathstring1 As String = Context.Request.CurrentExecutionFilePath.ToString()
sb2.Append("Current Executing File Path = " & pathstring1.ToString() & "<br />")
sb2.Append("Is Absolute = " & VirtualPathUtility.IsAbsolute(pathstring1).ToString() & "<br />")
sb2.Append("Is AppRelative = " & VirtualPathUtility.IsAppRelative(pathstring1).ToString() & "<br />")
sb2.Append("Make AppRelative = " & VirtualPathUtility.ToAppRelative(pathstring1).ToString() & "<br />")
Response.Write(sb2.ToString())

備註

虛擬路徑只能是根運算符(圖狀符號[~]),也可以從根運算符開始。 如果 virtualPathnull,則會引發 ArgumentNullException 例外狀況。 如果 virtualPath 是空字串 (“),則 IsAppRelative 方法會傳回 false

注意

"~ filename " 不是有效的虛擬路徑,會傳回 IsAppRelative 方法的 false

適用於

另請參閱