أعلى مُجيب
How to convert URI path to normal filepath?

السؤال
-
So, i have this "file:///E:/urban.jpg" and i want to convert it to "E:\urban.jpg". I tried that:
path = path.Replace("file:///", "").Replace(@"/", @"\"); but what i get is this E:\\urban.jpg instead of E:\urban.jpg
Why?26/ربيع الأول/1430 07:12 م
الإجابات
-
Thi should work :
string p = "file:///E:/urban.jpg";
p = new Uri(p).LocalPath;
Console.WriteLine(p);
http://blog.voidnish.com- تم وضع علامة كإجابة بواسطة Bin-ze Zhao 29/ربيع الأول/1430 05:58 ص
26/ربيع الأول/1430 07:18 مالمشرف -
"\\" corresponds to Backslash character
If you are watching the variable it will be displaying "E:\\urban.jpg" only. When you put it in a message box or writing to a file it will be taken as "E:\urban.jpg"
Regards,
Navin Narayan- تم وضع علامة كإجابة بواسطة Bin-ze Zhao 29/ربيع الأول/1430 05:59 ص
27/ربيع الأول/1430 12:43 م -
What you're seeing is called "string escaping", and it's completely normal. You should still get the proper output.
See the following article for more information:
http://www.yoda.arachsys.com/csharp/strings.html
David Morton - http://blog.davemorton.net/- تم وضع علامة كإجابة بواسطة Bin-ze Zhao 29/ربيع الأول/1430 05:58 ص
27/ربيع الأول/1430 12:53 مالمشرف
جميع الردود
-
Thi should work :
string p = "file:///E:/urban.jpg";
p = new Uri(p).LocalPath;
Console.WriteLine(p);
http://blog.voidnish.com- تم وضع علامة كإجابة بواسطة Bin-ze Zhao 29/ربيع الأول/1430 05:58 ص
26/ربيع الأول/1430 07:18 مالمشرف -
No, that's absolutelly the same. It returns "E:\\urban.jpg". Thanks anyway.27/ربيع الأول/1430 11:06 ص
-
"\\" corresponds to Backslash character
If you are watching the variable it will be displaying "E:\\urban.jpg" only. When you put it in a message box or writing to a file it will be taken as "E:\urban.jpg"
Regards,
Navin Narayan- تم وضع علامة كإجابة بواسطة Bin-ze Zhao 29/ربيع الأول/1430 05:59 ص
27/ربيع الأول/1430 12:43 م -
What you're seeing is called "string escaping", and it's completely normal. You should still get the proper output.
See the following article for more information:
http://www.yoda.arachsys.com/csharp/strings.html
David Morton - http://blog.davemorton.net/- تم وضع علامة كإجابة بواسطة Bin-ze Zhao 29/ربيع الأول/1430 05:58 ص
27/ربيع الأول/1430 12:53 مالمشرف