What is the best way to get the physical path to a file in C#?
UPDATE:
I have a file name but I don't want to hard code the path to it since it may change. I just know its relative path but not its physical path.
Logical File name is nothing but file path at Operating system level. use transaction <FILE> to view logical file path. Physical File path is nothing but file path at application server level.
Procedure. Procedure: In the SAP GUI, enter the transaction code FILE to open the Change View "Logical File Path Definition": Overview window. If a window opens with the message Caution: The table is cross-client. , press Enter.
For regular apps, Path.GetFullPath(path)
will return this. If this is web, then MapPath
is what you want (for example, Server.MapPath("~/foo/bar")
).
Re comments; try HttpContext.Current.Server.MapPath(...)
; in the absense of HttpServerUtility
(comments), then try VirtualPathUtility.ToAbsolute
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With