目录中ASP.NET中的DOS命令问题 [英] DOS command in ASP.NET problem in directories

查看:67
本文介绍了目录中ASP.NET中的DOS命令问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

//我希望dir命令在项目文件夹中执行,这意味着我希望这将显示项目文件夹的文件...

// I want dir command to execute in project folder which means I want that this will show the files of project folder...

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace filehider
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }
      
        protected void btnconvert_Click(object sender, EventArgs e)
        {
// i want this command execute in project folder means i want this will show the files of project folder...
            ExecuteCommandSync("dir");           
        }

        public void ExecuteCommandSync(string command)
        {
            System.Diagnostics.ProcessStartInfo procStartInfo =
                new System.Diagnostics.ProcessStartInfo("cmd", "/c");
            System.Diagnostics.Process proc = new System.Diagnostics.Process();
            proc.StartInfo = procStartInfo;
            proc.Start();
           
            procStartInfo.Arguments = command;
          
            procStartInfo.RedirectStandardOutput = true;
            procStartInfo.UseShellExecute = false;
  
            procStartInfo.CreateNoWindow = false;
           
            string result = proc.StandardOutput.ReadToEnd();
          
            Label3.Text = result;
        }
    }
}

推荐答案

在Windows中没有"dos命令"之类的东西.您在ASP.NET中尝试做的事情根本没有任何意义,并且通常会非常糟糕.

您需要使用System.IO.Directory.GetFiles,请参见 http://msdn.microsoft.com/en -us/library/system.io.directory.aspx [ Directory.Get .文件搜索模式问题 [ ^ ].

即使正确执行此操作,也向Web应用程序用户显示服务器本地文件看起来像是最疯狂和绝对不安全的活动.不要告诉我这有任何意义.

—SA
There is no such things as "dos command" in Windows. What are your trying to do in ASP.NET makes no sense at all and would be extremely bad in general.

You need to use System.IO.Directory.GetFiles, see http://msdn.microsoft.com/en-us/library/system.io.directory.aspx[^].

There is a little problem though, the solution is discussed here: Directory.Get.Files search pattern problem[^].

Even if you do this correctly, showing files local to the server to the user of Web application looks like most crazy and absolutely unsafe activity. Don''t tell me it can make any sense.

—SA


您可能会发现这篇文章很有趣:
在ASP.NET中浏览文件系统:新方法还是旧方法 [
You may find this article to be of some interest:
File System Browsing in ASP.NET: New Approach vs. Old Approach[^]

Best regards
Espen Harlinn


这篇关于目录中ASP.NET中的DOS命令问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆