我用vs打开一个项目。现在我想获取该项目下debug文件夹的路径。不使用openFileDialog。有什么语句可以实现吗?绝对,相对都可以。

解决方案 »

  1.   

    是在控制台中,还是在Form中?
      

  2.   

    1.获取和设置当前目录的完全限定路径。string str = System.Environment.CurrentDirectory;Result: C:\xxx\xxx2.获取启动了应用程序的可执行文件的路径,不包括可执行文件的名称。string str = System.Windows.Forms.Application.StartupPath;Result: C:\xxx\xxx3.获取新的 Process 组件并将其与当前活动的进程关联的主模块的完整路径,包含文件名。string str = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;Result: C:\xxx\xxx\xxx.exe4.获取当前 Thread 的当前应用程序域的基目录,它由程序集冲突解决程序用来探测程序集。string str = System.AppDomain.CurrentDomain.BaseDirectory;Result: C:\xxx\xxx\5.获取应用程序的当前工作目录。string str = System.IO.Directory.GetCurrentDirectory();Result: C:\xxx\xxx6.获取和设置包含该应用程序的目录的名称。string str = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;Result: C:\xxx\xxx\7.获取当前进程的完整路径,包含文件名。string str = this.GetType().Assembly.Location;Result: C:\xxx\xxx\xxx.exe8.获取启动了应用程序的可执行文件的路径,包括可执行文件的名称。string str = System.Windows.Forms.Application.ExecutablePath; Result: C:\xxx\xxx\xxx.exe
      

  3.   

     string s = Application.StartupPath;
                MessageBox.Show(s);
      

  4.   

    string spath = System.Windows.Forms.Application.StartupPath + "\\******";//****为文件夹名
      

  5.   

    string mypath = Application.StartupPath;
      

  6.   

    http://blog.csdn.net/donhao/archive/2010/06/01/5638257.aspx
    跨平台获取当前工作目录
      

  7.   

    前台获取方法
    html:<asp:FileUpload runat="server" id="CardUpload"></asp:FileUpload> 
           <input id="Import" onclick="GetUrl();" type="button" value="导入"  class="button" runat="server" />
          <asp:HiddenField ID="hidPath" runat="server" />
    js代码:
     function GetUrl() {
                //判断浏览器类型
                var isIE = (document.all) ? true : false;
                var isIE7 = isIE && (navigator.userAgent.indexOf('MSIE 7.0') != -1);
                var isIE8 = isIE && (navigator.userAgent.indexOf('MSIE 8.0') != -1);
                var file = document.getElementById("CardUpload");
                if (isIE7 || isIE8) {
                    file.select();
                    document.getElementById("hidPath").value = document.selection.createRange().text;
                    document.selection.empty();
                }
             }