1

I have been trying to implement something like this, but it will time out on the wait for exit?

My objective is to open the file on the client's machine in notepad. The below code is what i originally had, but just learned taht this will only work on the server ,not the client.

    public JsonResult Index()
    {
        System.Diagnostics.Process proc = new System.Diagnostics.Process();
        proc.EnableRaisingEvents = false;
        proc.StartInfo.UseShellExecute = false;
        proc.StartInfo.FileName = "notepad";

        proc.StartInfo.Arguments =  @"\\share\test.XML";
        proc.Start();
        proc.WaitForExit();
    }

Is there a way to do this?

All i am trying to do is open the test.xml file on a client's machine.

5
  • 1
    Process.Start will execute on the server side. It is highly unlikely that you want a bunch of notepad windows opening in the server. Commented Jul 16, 2012 at 19:12
  • are you trying to make the Index Action wait? Commented Jul 16, 2012 at 19:13
  • possible duplicate of How to open command prompt from my application @Client side Commented Jul 16, 2012 at 19:13
  • @some_bloody_fool this is an example code of your's by exactly are you trying to achieve Commented Jul 16, 2012 at 19:14
  • @HatSoft Nope, I just want to open the file on the client's machine in notepad, i will reword thsi Commented Jul 16, 2012 at 19:16

3 Answers 3

1

The code you have there will execute on the server side; not on the client-side. You can't open a file (or execute a program for that matter) on the client machine, from a browser. That would be a major security issue if a browser could do that.

Best thing you can do is either create a hyperlink to the file in the format file:///drive:/file.xml

Sign up to request clarification or add additional context in comments.

2 Comments

yeah, woops Oded pointed that out, i guess then that i am asking how to open teh file on the client's machine in notepad
You can't force the file to be opened in Notepad. The user will have to choose which program he wants to use to open the file or the OS system will decide automatically based on which program is registered as the handler for that type of document. If the user has Explorer as the handler for XML files, then that's what the OS will use to open it if that's what the user chooses to do.
0

Your code will start the notepad application and open the test.xml file in correctly

The notepad application will left open till it is close because you are using the WaitForExit method.

The WaitForExit method instructs the Process component to wait indefinitely for the associated process to exit.

Do you really want to use the WaitForExit in your MVC action

Please read the Remarks taken from MSDN for WaitForExit

The WaitForExit() overload is used to make the current thread wait until the associated process terminates. This method instructs the Process component to wait an infinite amount of time for the process and event handlers to exit. This can cause an application to stop responding. For example, if you call CloseMainWindow for a process that has a user interface, the request to the operating system to terminate the associated process might not be handled if the process is written to never enter its message loop.

Note: In the .NET Framework version 3.5 and earlier versions, the WaitForExit() overload waited for MaxValue milliseconds (approximately 24 days), not indefinitely. Also, previous versions did not wait for the event handlers to exit if the full MaxValue time was reached.

Comments

0

my weight the same and so I resolved using this

   using System.Xml;

   XmlTextReader reader = new XmlTextReader(
   Server.MapPath("mycompany.xml"));

    reader.WhitespaceHandling = WhitespaceHandling.None;
    XmlDocument xmlDoc = new XmlDocument();
    xmlDoc.Load(reader);
    reader.Close();        
    lbNodes.Items.Add("XML Document");
    XmlNode xnod = xmlDoc.DocumentElement;
    AddWithChildren(xnod, 1);

the complete example you can see here http://www.codeproject.com/Articles/4902/Reading-an-XML-file-using-NET

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.