locked
Checking the file status RRS feed

  • Question

  • User-614943948 posted
    Process[] process = Process.GetProcessesByName("excel");
    foreach (Process excel in process)
    {
    excel.Kill();
    
    }
    process = null;

    I am using this program to kill Excel process. Before killing i want to find out, for how long is the file open. How can i accomplish this?

    Tuesday, October 17, 2017 10:57 AM

All replies

  • User753101303 posted

    Hi,

    If you look at the documentation for the Process class, you'll see you could try https://msdn.microsoft.com/en-us/library/system.diagnostics.process.starttime(v=vs.110).aspx

    Trying to use Excel on a web server is one of the very last thing I would ever try. If you can use a programming Library such as Open XML SDK or some other Library that deals with this file format.

    If for now you tried only on your own machine, keep in mind that once deployed on a real web server it will run server side ie you won't be able to control a client side Excel instance this way if this is what you are trying to do.

    Tuesday, October 17, 2017 1:25 PM
  • User-707554951 posted

    Hi  maverick786us,

    For you problem, you could get StartTime for each process.

    Then you could get difference between the StartTime and current time:

                Process[] process = Process.GetProcessesByName("excel");
                foreach (Process excel in process)
                {
                    DateTime dt = excel.StartTime;
                    DateTime dt3 = DateTime.Now;
                    TimeSpan ts2 = dt3.Subtract(dt);
                    Response.Write(ts2);
                    excel.Kill();                                       
                }
                process = null;

    Related links:

    https://msdn.microsoft.com/en-us/library/system.diagnostics.process(v=vs.110).aspx

    https://msdn.microsoft.com/en-us/library/8ysw4sby(v=vs.110).aspx

    Best Regards

    Cathy

    Wednesday, October 18, 2017 6:39 AM
  • User-614943948 posted

    What happens is the users who are uploading, downloading the file, when they open those excel files in their client machines, i don't know why it creates those process in the server. If I don't kill that process, the end users face problems while opening the files again.

    Friday, October 27, 2017 9:11 AM
  • User-707554951 posted

    Hi  maverick786us,

    What happens is the users who are uploading, downloading the file, when they open those excel files in their client machines

    I supposed that an error will be raise

    You could take a try.

    Best Regards

    Cathy

    Friday, October 27, 2017 9:49 AM
  • User753101303 posted

    It's really unclear. So far your only worked on your own machine ?

    Your code will search an Excel process on the web server side and will have absolutely no effect at all on client side Excel instances.

    Friday, October 27, 2017 2:31 PM