Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
// 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;
        }
    }
}
Posted
Updated 25-Jun-11 15:44pm
v2

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
 
Share this answer
 
v2
Comments
Espen Harlinn 25-Jun-11 10:38am    
My 5 :)
Sergey Alexandrovich Kryukov 25-Jun-11 16:55pm    
Thank you, Espen.
--SA
thatraja 25-Jun-11 12:25pm    
Simple way, 5!
Sergey Alexandrovich Kryukov 25-Jun-11 16:55pm    
Thank you, Raja.
--SA
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
 
Share this answer
 
Comments
thatraja 25-Jun-11 12:25pm    
Looks cool, 5! BTW bookmarked the article.
Espen Harlinn 25-Jun-11 12:28pm    
Thank you thatraja - I liked it too :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900