e.g.
I wanted to convert a local windows path in the form:
"C:\Documents and Settings\William Tell\My Documents\TestClient"
to the form:
"file:///C:/Documents%20and%20Settings/William%20Tell/My%20Documents/TestClient"
This conversion is supported by the framwork System.Uri class.
Here is some code:
string localPath = @"C:\Documents and Settings\William Tell\My Documents\TestClient";
Uri uri = new Uri( localPath );
string absoluteUri = uri.AbsoluteUri;
The value of absoluteUri is:
"file:///C:/Documents%20and%20Settings/William%20Tell/My%20Documents/TestClient"
Conversely, we can convert the uri back to a local path as follows:
string absoluteUri = @"file:///C:/Documents%20and%20Settings/William%20Tell/My%20Documents/TestClient";
Uri uri = new Uri( absoluteUri );
string localPath = uri.LocalPath;
The value of local path is:
""C:\\Documents and Settings\\William Tell\\My Documents\\TestClient"
Hope somebody finds this helpful.
No comments:
Post a Comment