Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am running asp.net website on IIS its run on service. and I want to open Excel file with GUI, so I must use the active session.


What I have tried:

This is my aspx file:
ASP.NET
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication2.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
    </form>
</body>
</html>


This is my aspx.cs file:
C#
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using murrayju.ProcessExtensions;

namespace WebApplication2
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string x = @"C:\www\zmqpga.com\reports\F.xlsx";
            ProcessExtensions.StartProcessAsCurrentUser(x);
        }
    }
}

It makes the next error http://prntscr.com/g4q1uo

And when I use another solution like
C#
System.Diagnostics.Process process1 = new System.Diagnostics.Process();
    process1.StartInfo.WorkingDirectory = Request.MapPath("~/");
    process1.StartInfo.FileName = Request.MapPath("F.xlsx");
    process1.StartInfo.Arguments = " ";
    process1.StartInfo.LoadUserProfile = true;
    process1.Start();
    process1.WaitForExit();
    process1.Close();


It's open the Excel process(when I look at task manager). But I need the GUI so I have to run It on the active session. Anyone know an easy way to do so? can you give me any example code? I just have no idea...

for ProcessExtensions, I use this https://github.com/murrayju/CreateProcessAsUser

For the second solution after a lot of tries when I use remote debugging I just getting stuck on process1.Start(); and after time out I got an error on process1.WaitForExit(); because of

C#
An exception of type 'System.InvalidOperationException' occurred in System.dll 
but was not handled in user code


Additional information: No process is associated with this object.
Hope for that someone will help, Thanks
Posted
Comments
Kornfeld Eliyahu Peter 6-Aug-17 6:20am    
Are you clear on this? It will - if and when - open the Excel file on the server! Who will look at it? And what will you do if 12345 users ask to do this process? Open 12345 Excel files on the server?!
Member 9965700 6-Aug-17 6:55am    
I have no problem right now of more than 1 user for now on the same time.
I will explain The problem
I have xltm file that runs VB code(I have to use this Excels file as is).
This VB code Open Excel WorkBook and update it on the GUI
(That what I think it do) And because It has no GUI on session 0. This program gets stuck on process1.Start();
And do not run the file...
Maybe do you have an idea to solve it in another way?
Member 9965700 6-Aug-17 8:41am    
any idea?
Kornfeld Eliyahu Peter 6-Aug-17 8:43am    
How could I gave you any idea, if you do not answer my questions...
Member 9965700 7-Aug-17 0:33am    
Are you clear on this? It will - if and when - open the Excel file on the server! Who will look at it?
- This Excel file run vb code it uses a workbook and must be able to use GUI for work well... no one will look at it, but the program must use it (That what I think maybe I got understand the problem...) That I think Because on Debug mode it works good (on user session) when using remote console application (on user session) It works well.
The problem is start when using the asp.net website on IIS as service and start trying to run the Excel file from it (session 0)...


And what will you do if 12345 users ask to do this process? Open 12345 Excel files on the server?!.
- Actually, I have no problem right now of 12345 users...
I have the problem of maximum 5,6 on the same time...
I think the machine can be able to handle this...
So the answer is yes Theory for 12345 users it will open 12345 files
But again I don't want to waste my time to solve hard problems and I will need have to really deal with them in real life, but only in theory...

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