共用方式為


VirtualPathUtility.GetExtension(String) 方法

定義

擷取虛擬路徑中參考的副檔名。

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

參數

virtualPath
String

虛擬路徑。

傳回

副檔名字串常值 (String Literal),包含句號 (.)、null 或空字串 ("")。

例外狀況

virtualPath 包含一或多個無效字元,如 InvalidPathChars 中所定義。

範例

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

StringBuilder sb = new StringBuilder();
String pathstring = Context.Request.FilePath.ToString();
sb.Append("Current file path = " + pathstring + "<br />");
sb.Append("File name = " + VirtualPathUtility.GetFileName(pathstring).ToString() + "<br />");
sb.Append("File extension = " + VirtualPathUtility.GetExtension(pathstring).ToString() + "<br />");
sb.Append("Directory = " + VirtualPathUtility.GetDirectory(pathstring).ToString() + "<br />");
Response.Write(sb.ToString());
Dim sb As New StringBuilder()
Dim pathstring As String = Context.Request.FilePath.ToString()
sb.Append("Current file path = " & pathstring & "<br />")
sb.Append("File name = " & VirtualPathUtility.GetFileName(pathstring).ToString() & "<br />")
sb.Append("File extension = " & VirtualPathUtility.GetExtension(pathstring).ToString() & "<br />")
sb.Append("Directory = " & VirtualPathUtility.GetDirectory(pathstring).ToString() & "<br />")
Response.Write(sb.ToString())

備註

如果傳遞至 GetExtension 方法的虛擬路徑是 "/images/image1.gif" ,則傳回的延伸模組為 ".gif"

適用於

另請參閱