باسلام
توی پروژم توسط folderBroserDialog یه آدرسی رو داخل یه متغییر استرینگ ذخیره کردم مثلا (c:\program) اما حالاکه میخوام از اون آدرس استفاده کنم
باید به شکل (c:\\program) ویا ("c/program"@) باشه که نیست
حالا باید چیکارکنم که آدرس به صورت استاندارد C# ذخیره بشه.
ممنون
در کجا میخواهید استفاده کنید ؟
مشکلی نباید داشته باشه
ممنون از پاسخگوییتون
برای مثال من آدرس مورد نظر رو در string p=c:\program ذخیره کردم حالا میخوام بدونم این آدرس وجود داره یانه (directory.exist(p یا اینکه میخوام یک فایل رو انتقال بدم به آدرس p
مثلا (file.move(s,p ولی نمیشه و فایل به فولدری که پروژه درآن قرارداده منتقل میشه.
از Path.Combine استفاده کنید
using System; using System.IO; public class ChangeExtensionTest { public static void Main() { string path1 = "c:\\temp"; string path2 = "subdir\\file.txt"; string path3 = "c:\\temp.txt"; string path4 = "c:^*&)(_=@#'\\^.*(.txt"; string path5 = ""; string path6 = null; CombinePaths(path1, path2); CombinePaths(path1, path3); CombinePaths(path3, path2); CombinePaths(path4, path2); CombinePaths(path5, path2); CombinePaths(path6, path2); } private static void CombinePaths(string p1, string p2) { try { string combination = Path.Combine(p1, p2); Console.WriteLine("When you combine '{0}' and '{1}', the result is: {2}'{3}'", p1, p2, Environment.NewLine, combination); } catch (Exception e) { if (p1 == null) p1 = "null"; if (p2 == null) p2 = "null"; Console.WriteLine("You cannot combine '{0}' and '{1}' because: {2}{3}", p1, p2, Environment.NewLine, e.Message); } Console.WriteLine(); } } // This code produces output similar to the following: // // When you combine 'c:\temp' and 'subdir\file.txt', the result is: // 'c:\temp\subdir\file.txt' // // When you combine 'c:\temp' and 'c:\temp.txt', the result is: // 'c:\temp.txt' // // When you combine 'c:\temp.txt' and 'subdir\file.txt', the result is: // 'c:\temp.txt\subdir\file.txt' // // When you combine 'c:^*&)(_=@#'\^.*(.txt' and 'subdir\file.txt', the result is: // 'c:^*&)(_=@#'\^.*(.txt\subdir\file.txt' // // When you combine '' and 'subdir\file.txt', the result is: // 'subdir\file.txt' // // You cannot combine '' and 'subdir\file.txt' because: // Value cannot be null. // Parameter name: path1
هیچ کاربری تا کنون از این پست تشکر نکرده است
با ما تماس بگیرید تا در این مسیر همراهتان باشیم :)