Reputation: 95
i have a string like this: D:\\folder\\folder\\folder/folder/folder since it is mixed up with forward and backword slashes the directory couldnt find file but if i change it like this D:\folder\folder\folder\folder\folder the path is correct .
i have try to do it like this
sourceStreamId=D:\\folder\\folder\\folder/folder/folder
string appdomain = HttpRuntime.AppDomainAppPath;
string destinationFile=System.IO.Path.Combine(appdomain,sourceStreamId).Replace("\\", @"\");
but this resulted in a string like this D:\\folder\\folder\\folder/folder/folder
can anybody sugest a work around for this
i have been here:How to replace the double backslash with a single backslash but that string only have double backword slash i have both forward and backword
Upvotes: 0
Views: 242
Reputation: 5194
You could leverage Path to fix it for you:
var ourceStreamId = "D:\\folder\\folder\\folder/folder/folder";
var path = Path.GetFullPath(ourceStreamId);
Console.WriteLine(path);
//output: D:\folder\folder\folder\folder\folder
Upvotes: 0
Reputation: 3316
try as below:-
string destinationFile=System.IO.Path.Combine(appdomain,sourceStreamId).Replace(@"\\", @"\");
Eg:-
string path = "C:\Hg\temp/test\\LogFile.txt";
path = path.Replace(@"\\", @"\");
string output = path.Replace(@"/", @"\");
output >>> C:\Hg\temp\test\LogFile.txt
Upvotes: 1
Reputation: 7213
To replace bot just call Replace
twice:
string destinationFile = System.IO.Path.Combine(appdomain,sourceStreamId)
.Replace(@"\\", @"\")
.Replace("/", @"\");
References: DotNetFiddle Example
Upvotes: 0