views:

280

answers:

2

Hi all,

I have written an ASP.NET web page with C# behind that runs an existing vb script.

The idea is that the user uploads an Excel spreadsheet (.xls) using the web page, the C# does a few basic checks on the file (file type, file name etc) then saves the .xls to a network location.

The C# then passes the network path of the .xls to the vb script, which gets the required information from the .xls to create a .csv file.

Finally the .csv is passed into a stored procedure and uploaded to a database table.

The problem is that all this runs perfectly when I run the webpage locally on my machine. However when I upload the page to the webserver it does not seem to execute the vb script; instead it just sits there waiting for the script to exit.

Some quick info:

  • Excel is installed on the web server
  • The website is set to execute scripts and executables
  • The script is currently set to 'run as' my personal domain login (this has to change) which has admin on the web server
  • If I run the script on the webserver using the cmd prompt it works

I'd really appreciate any ideas on what might be going wrong... seriously, I'm pulling my hair out over this one and will consider any idea, no matter how crazy... but, and it's a big one, despite the fact that that there are many other ways of achieving the same result, I'm afraid that for a number of reasons this is what I have to work with :)

Edit

Here is how I call the script

                try
                {
                    System.Security.SecureString password = new System.Security.SecureString();

                    string uspw = "mypassword";
                    foreach (char c in uspw)
                    {
                        password.AppendChar(c);
                    }

                    Process scriptProc = new Process();
                    scriptProc.StartInfo.FileName = @"cscript";
                    scriptProc.StartInfo.Arguments = scriptPath + " //Nologo " + uploadPath + xlsFileName;
                    scriptProc.StartInfo.WindowStyle = ProcessWindowStyle.Minimized;
                    scriptProc.StartInfo.UserName = "myusername";
                    scriptProc.StartInfo.Password = password;
                    scriptProc.StartInfo.UseShellExecute = false;
                    scriptProc.Start();
                    scriptProc.WaitForExit();
                    scriptProc.Close();

                }
                catch...

All of the file paths are relative.

The code seems to fail when the script is called. You can clearly see the page waiting for the script to finish. However if you watch the task manager on the web server neither cscript or excel start to run.

I've also stuck a message box right at the start of the script which does not get displayed

Edit 2 It turns out that cscript is running, I just needed to tick the 'All Users' check box in the task manager... I'm still none the wiser though!

Thanks so much in advance

+1  A: 

Without seeing the code this is a blind guess - I suggest you check how you are specifying the path to the vb script - make sure you are not using an absolute path, and that the file is in the same location relative to the C# page on the server as it is on your machine.

Bork Blatt
Thanks for your reply, please see my edit
oookiezooo
+1  A: 

Sounds like you are using automation to control the Excel application itself?

Some quick info:

  • Excel is installed on the web server

That is generally a bad idea, because the Excel application is not an application that is intended to be automated by a server. Thing might hang because the application is waiting for user input in a dialog somewhere. And it's not scalable for handling operations from multiple users simultaneously.

If the final goal is to extract the data from the excel file and put it in an sql server, I would rather suggest that you use the Jet OLEDB provider to retrieve the data from the excel file, either from your web application, and letting that feed the data into sql server, or let the sql server do it directly. If there is a lot of data in the excel file, the latter might be the best choice

Pete