Reputation: 6778
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
Reputation: 17048
This will return the virtual path:
Page.TemplateSourceDirectory
See the below answers for the physical path.
Upvotes: 1
Reputation: 2679
Use the GetParent()
method on Directory.
DirectoryInfo parent = Directory.GetParent(requestPath);
Upvotes: 0
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
Reputation: 1102
you can get Directory Path from System.IO.FileInfo
var fInfo = new System.IO.FileInfo(path);
var result = fInfo.DirectoryName;
Upvotes: 0