Click here to Skip to main content
15,557,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: (untagged)
string path="D:/'"+variable+"'/"+variable2";
string[] files=Directory.Getfiles(path);
this code generate thats output: D:/folder/folder2\\file
but this got error path not supported and i want this path
output: D:/folder/fodler2/file
plz help me........thanks
Posted
Updated 22-Aug-14 23:08pm
v2

Start by looking at Path.Combine[^] - it builds paths better than string concatenation because it intelligently looks at the data and "rationalises" it.

C#
string variable = @"Temp\";
string variable2 = @"wzdd89\";
string path = "D:/'" + variable + "'/" + variable2;
string betterPath = Path.Combine(@"D:\", variable, variable2);
string[] files = Directory.GetFiles(betterPath);
 
Share this answer
 
Windows file paths use \ not / and to put a \ in a c# string you need to escape it with another \ like the following:
C#
string path="D:\\"+variable+"\\"+variable2";
 
Share this answer
 
Comments
Member 11024166 23-Aug-14 5:35am    
but if i given this path to attachment then error come the given path not supported
C#
string variable = @"'"+foldername+"'\"";
                                 string variable2 = @"'" + files2[i] + "'\"";
                                 string path = "D:/'" + variable + "'/" + variable2;
                                 string betterPath = Path.Combine(@"D:\", variable, variable2);
                                 string[] files = Directory.GetFiles(betterPath);


i use this but error come illegal character in path
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900