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:
<%@ 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:
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
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
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