
March 18th, 2003, 07:50 PM
|
|
Registered User
|
|
Join Date: Mar 2003
Posts: 1
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
Help Starting a Process from asp.net
Hello, <br><br>I am trying to Automate MSAccess in order to generate snapshot reports online. I have based my code on MSDN KB article# 317114. <br>http://support.microsoft.com/default.aspx?scid=kb;en-us;317114 <br><br>Below is a code sample. <br><br><br>private void OpenAccess() <br>{ <br> string sDBPath = "C:\WebRptTest_01.mdb"; <br> string sAccPath = "C:\Program Files\Microsoft Office\Office10\MSACCESS.EXE"; <br> string sCmdLine = """" + sDBPath + """"; <br> Access.Application oAccess = null; <br> Process p = null; <br><br> ProcessStartInfo startInfo = new ProcessStartInfo(); <br> startInfo.FileName = sAccPath; <br> startInfo.Arguments = sCmdLine; <br> startInfo.WindowStyle = ProcessWindowStyle.Maximized; <br><br> p = Process.Start(startInfo); <br> p.WaitForInputIdle(60000); //max 1 minute wait for idle input state <br><br> // Move focus back to this form. This ensures that Access <br> // registers itself in the ROT: <br> //this.Activate(); <br><br> // Pause before trying to get Application object: <br> System.Threading.Thread.Sleep(1000); <br><br> oAccess = (Access.Application) Marshal.BindToMoniker(sDBPath); <br>} <br><br><br>My problem is that every time I get to the line that uses "Marshal.BindToMoniker" another instance of Access is started instead of grabbing the running instance. I have narrowed the cause down to one of 2 problems: <br><br>1) (Most probable) I don't believe that the command line arguments are being executed when the process is started. That being the case, Access is starting up without opening a file. Thus when the Marshal.BindToMoniker line is called, it begins a new instance using the sDBPath. Can anyone tell me why the command line arguments would not be executed? Am I starting the process wrong? <br><br><br>2) It is also possible that Access is not registering itself in the ROT. Office products do not register themselfs in the ROT until they lose focus. In the KB code, they use WinForms and call this.Activate() in order for office to lose focus. How can I do this when using asp.net? I have no window to move the focus too. <br><br><br>Any help is greatly appreciated! <br><br>----mike
|