Calling console application from asp.net - asp.net

I try to call console appliction from asp.net when i put breakpoint in console app why it can't stop there.How can i call console application?
var proc = Process.Start("D:\\Edefter\\EFaturaConsoleTxtParser\\bin\\Debug\\EFaturaConsoleTxtParser.exe", "/arg1 /arg2");
proc.WaitForExit();

I'm not sure about this but anyway you can try
ProcessStartInfo startinfo = new ProcessStartInfo();
startinfo.FileName =#"D:\\Edefter\\EFaturaConsoleTxtParser\\bin\\Debug\\EFaturaConsoleTxtParser.exe";
startinfo.CreateNoWindow = true;
startinfo.UseShellExecute = true;
Process myProcess = Process.Start(startinfo);
myProcess.Start();

While starting a process programmatically, the 'UserShellExcute' property must be 'false'. Otherwise, the CreateNoWindow property value gets ignored and new window is created.
Example:
ProcessStartInfo startinfo = new ProcessStartInfo();
startinfo.FileName = #"demoApplication.exe";
startinfo.Arguments = "arg1 arg2";
startinfo.CreateNoWindow = true;
startinfo.UseShellExecute = false;
Process myProcess = Process.Start(startinfo);
Source: http://msdn.microsoft.com

Related

How to use Windows task Scheduler in ASP.NET

I am trying to use ASP.NET in Window Task Scheduler. I want to send the email on specific time.
But ASP.NET is not run as an EXE, it has a dynamic ip address.
I have no idea to use Window Task Scheduler in ASP.NET.
Can you give me any solutions for it?
void SendEmail()
{
//get the data from database
DataTable data = GetData();
DataTable email_data = GetEmailData();
//set DataTable Name of Excel Sheet
data.TableName = "NSOList";
//Create a New Workook
using (XLWorkbook wb = new XLWorkbook())
{
//Add the DataTable as Excel Workhseet
wb.Worksheets.Add(data);
using (MemoryStream memoryStream = new MemoryStream())
{
//Save the Excel Workbook to MemoryStream
wb.SaveAs(memoryStream);
//Convert MemoryStream to Byte array
byte[] bytes = memoryStream.ToArray();
memoryStream.Close();
//body with embedded image
AlternateView body = AlternateView.CreateAlternateViewFromString
("Hi <br><br> <img src=cid:example>", null, "text/html");
//create the LinkedResource (embedded image)
LinkedResource image = new LinkedResource("c:\\example.png");
image.ContentId = "example";
//add the LinkedResource to the appropriate view
body.LinkedResources.Add(image);
String from = "abcd#abcd.net";
//bring Email data
for (int i = 0; i < email_data.Rows.Count; i++)
{
String to = email_data.Rows[i][0].ToString();
using (MailMessage mm = new MailMessage(from, to))
{
SmtpClient smtp = new SmtpClient();
mm.Subject = "List";
mm.AlternateViews.Add(body);
mm.Attachments.Add(new Attachment(new MemoryStream(bytes), "NSOList.xlsx"));
mm.IsBodyHtml = true;
smtp.Host = "smtp.gmail.com";
smtp.EnableSsl = true;
System.Net.NetworkCredential credentials = new System.Net.NetworkCredential();
credentials.UserName = "abcd#gmail.com";
credentials.Password = "abcd";
smtp.UseDefaultCredentials = true;
smtp.Credentials = credentials;
smtp.Port = 587;
smtp.Send(mm);
}
}
}
}
}
You should use a Task Scheduler like Quartz.Net. It allows you to define classes as Jobs, and then execute those jobs according to an schedule. I'm currently using it in some in-house projects and it performs as advertised.
EDITED
Check the answers here.
It should be a console application with your code in it. In bin folder it will create a .exe file which you need to use it in windows task scheduler.
Following link provides you a step by step procedure on how to create a task in windows task scheduler.
http://www.digitalcitizen.life/how-create-task-basic-task-wizard

how to write file pdf when i convert html to pdf

i try to use wkhtmltopdf.exe from server to convert html file to pdf then when process is done. application must to create file pdf . How can i do ? Please help.
this is code
string myDocumentsPath = "c:\\wkhtmltopdf.exe ";
ProcessStartInfo psi = new ProcessStartInfo(myDocumentsPath, " http://www.website.com/page");
psi.UseShellExecute = false;
psi.RedirectStandardOutput = true;
psi.RedirectStandardInput = true;
psi.RedirectStandardError = true;
psi.CreateNoWindow = true;
Process myProcess = Process.Start(psi);
myProcess.WaitForExit();
myProcess.Close();

I can't send email in asp .net

When i send email there is an exception which says "failure sending mail".
var mailObj = new MailMessage("marabifuad2013#gmail.com", "to Email");
mailObj.Subject = "subject";
mailObj.Body ="";
mailObj.IsBodyHtml = true;
var smtpServer = new SmtpClient("smtp.gmail.com", 587);
smtpServer.Credentials = new NetworkCredential("marabifuad2013#gmail.com", "password");
smtpServer.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpServer.Send(mailObj);
I guess that because you haven't specified to use SSL:
smtpServer.EnableSsl = true;
Also you can try:
smtpServer.UseDefaultCredentials = true;
Apart from that everything looks fine, providing that you entering correct credentials and etc.

how can i read output from console in asp.net

i am trying to read output from .exe file of a c++ program and trying to use this output for further use in my asp.net web application but it isn't working
this is what i have done so far
System.Diagnostics.Process MyProcess = new System.Diagnostics.Process();
MyProcess.StartInfo.CreateNoWindow = true;
MyProcess.StartInfo.UseShellExecute = false;
MyProcess.StartInfo.RedirectStandardOutput = true;
MyProcess.StartInfo.WorkingDirectory = "C:\\Users\\Hussain\\Documents";
MyProcess.StartInfo.FileName = "demo.exe";
MyProcess.StartInfo.Arguments = "MyArgument";
MyProcess.Start();
String s = MyProcess.StandardOutput.ReadToEnd();
System.IO.StreamWriter file = new
System.IO.StreamWriter("C:\\Users\\Hussain\\Documents\\123.txt");
file.WriteLine(s);
file.Close();
MyProcess.WaitForExit();
MyProcess.Close();

IIS session ends when external process run from ASP.NET

I have problem during running external process from ASP.NET application.
The process is run as follows:
[WebMethod(EnableSession = true)]
[ScriptMethod(UseHttpGet = false, ResponseFormat = ResponseFormat.Json)]
public static WebResult generateSomething(string language)
{
ProcessStartInfo psi = new ProcessStartInfo();
psi.UseShellExecute = false;
psi.RedirectStandardError = true;
psi.RedirectStandardOutput = true;
psi.RedirectStandardInput = true;
psi.WindowStyle = ProcessWindowStyle.Hidden;
psi.CreateNoWindow = true;
psi.ErrorDialog = false;
psi.WorkingDirectory = Environment.CurrentDirectory;
psi.FileName = String.Format("\"{0}\"", Path.Combine(appDir, Properties.Settings.Default.PATH_TO_APP_TEXT));
psi.Arguments = arguments.ToString();
modeller.log.Info("Arguments: " + psi.Arguments);
var outputText = new StringBuilder();
int exitCode;
var result = new WebResult();
using (Process process = new Process())
{
process.StartInfo = psi;
process.OutputDataReceived += (sendingProcess, args) => { outputText.Append(args.Data); };
process.ErrorDataReceived += (sendingProcess, args) => { outputText.Append(args.Data); };
process.Start();
process.BeginOutputReadLine();
process.BeginErrorReadLine();
process.WaitForExit();
exitCode = process.ExitCode;
}
string outText = outputText.ToString();
Immediately after process finishes (succesfully or not) and the method leaves ASP.NET IIS session is ended, so any authentication context via cookie breaks.
Can anyone help with this issue?
Thanks in advance

Resources