Process Worker Web Service (.exe Starter)


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.IO;
using System.Diagnostics;
using System.Security.Principal;
using System.Security;
using System.Runtime.InteropServices;

namespace ProWS
{
    /// <summary>
    /// Summary description for Service1
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
    // [System.Web.Script.Services.ScriptService]
    public class Pro: System.Web.Services.WebService
    {

        [WebMethod]
        public bool ProWorker(string filePath)
        {

            string htm = ".htm";
            string iFileName = Path.GetFileName(filePath);
            string oFileName = iFileName.Substring(0, iFileName.IndexOf(htm));
            string newFilePath = filePath.Substring(0, filePath.IndexOf(iFileName));

            try
            {
                ProcessStartInfo startInfo = new ProcessStartInfo();
                startInfo.CreateNoWindow = true;
                startInfo.UseShellExecute = false;
                //.xls dosyanın nereye kaydedileceği burada belirtilmelidir.
                //startInfo.WorkingDirectory = "D:\\XXX\\temp\\";
                startInfo.WorkingDirectory = "C:\\ XXX \\temp\\";
                //Rep2excel.exe dosyası proje dosyları arasına kopyalanmalıdır.
                startInfo.FileName = Server.MapPath(" XXX .exe");
                startInfo.RedirectStandardError = true;
                startInfo.RedirectStandardOutput = true;
                startInfo.Arguments = "-i:" + newFilePath + iFileName + " -o:" + "C:\\XXX\\temp\\" + oFileName + ".xls";


                using (Process process = Process.Start(startInfo))
                {
                    process.WaitForExit();
                    //if (process.ExitCode == 0) { }
                    process.Close();
                    return true;
                }

            }
            catch (Exception e)
            {
                return false;
                throw;
            }

        }

    }
}

Comments

Popular posts from this blog

Solution for "Can not obtain Oracle client information from registry"

Fix for "Websites cannot be started unless both the Windows Activation Service (WAS) and the World Wide Web Publishing Service (W3SVC) are running, Both services are currently stopped"

Solution for the fault: "System.Diagnostics.Process.Start is not working on IIS, but working on ASP.NET Development Server"