比如 string path = @"D:\[User]\Documents\Visual Studio 2008\Projects\GaoYing\src\DataFeed\DataFeed\bin\Debug\config.xml"怎么让他在控制台显示时只显示 "D:\~\Debug\config.xml"?
难道要手动处理?

解决方案 »

  1.   

    我只想到这个...   string path = @"D:\[User]\Documents\Visual Studio 2008\Projects\GaoYing\src\DataFeed\DataFeed\bin\Debug\config.xml";            string _FilePath = path.Substring(0, 3) + "~\\";            System.IO.FileInfo _FileInfo = new System.IO.FileInfo(path);            _FilePath += _FileInfo.Directory.Name + "\\" + _FileInfo.Name;
      

  2.   

     没有明白楼主的意思?
    Directory.GetCurrentDirectory();
    方法,获取应用程序的当前工作目录。你为什么要加载那么长的目录了?
    这是具体的代码?MSDN上的。
    using System;
    using System.IO;class Test 
    {
        public static void Main() 
        {
            try 
            {
                // Get the current directory.
                string path = Directory.GetCurrentDirectory();
                string target = @"c:\temp";
                Console.WriteLine("The current directory is {0}", path);
                if (!Directory.Exists(target)) 
                {
                    Directory.CreateDirectory(target);
                }            // Change the current directory.
                Environment.CurrentDirectory = (target);
                if (path.Equals(Directory.GetCurrentDirectory())) 
                {
                    Console.WriteLine("You are in the temp directory.");
                } 
                else 
                {
                    Console.WriteLine("You are not in the temp directory.");
                }
            } 
            catch (Exception e) 
            {
                Console.WriteLine("The process failed: {0}", e.ToString());
            }
        }
    }
      

  3.   

    我就是要把Directory.GetCurrentDirectory(); 取得目录显示出来啊,我的那个字符串只是模拟个很长的路径而已
    我我嫌显示的太长了,能不能缩掉一些而已,想知道有没有现成的类或方法