shamim
shamim

Reputation: 6778

How can get the current virtual path without file name?

Request.Path will get the current Path name with file name such as:

C:/......./Personal/Items.aspx

How can I get the only Path name such as:

C:/......./Personal

Upvotes: 1

Views: 1141

Answers (4)

David Neale
David Neale

Reputation: 17048

This will return the virtual path:

 Page.TemplateSourceDirectory

See the below answers for the physical path.

Upvotes: 1

Louis Marascio
Louis Marascio

Reputation: 2679

Use the GetParent() method on Directory.

DirectoryInfo parent = Directory.GetParent(requestPath);

Upvotes: 0

Quartermeister
Quartermeister

Reputation: 59179

You can use Path.GetDirectoryName to get the directory part of a path.

var path = System.IO.Path.GetDirectoryName(@"C:\Personal\Items.aspx");
// path is @"C:\Personal"

Upvotes: 2

Andrew
Andrew

Reputation: 1102

you can get Directory Path from System.IO.FileInfo

var fInfo = new System.IO.FileInfo(path);
var result = fInfo.DirectoryName;

Upvotes: 0

Related Questions