I have a little asp.net program that in this program i could write and run commands of command prompt in my asp.net application An important part of this story is to run exe files with commands.
It is my code but dont run exe file for example where i write mspaint it dont open:
<pre lang="c#">
try
{
Process p = new Process();
p.StartInfo.CreateNoWindow = false;
p.StartInfo.FileName = c_path.Value = Encoding.Default.GetString(Convert.FromBase64String(c_path.Value));
c_text.Value = Encoding.Default.GetString(Convert.FromBase64String(c_text.Value));
p.StartInfo.Arguments = c_text.Value;
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.Start();
string[] Uoc = new string[20];
for (int i = 1; Uoc.Length > i; i++)
{
Uoc[i] = p.StandardOutput.ReadLine();
Uoc[i] = Uoc[i].Replace("<", "<");
Uoc[i] = Uoc[i].Replace(">", ">");
Uoc[i] = Uoc[i].Replace("\r\n", "<br>");
}
string txt = "";
foreach (var item in Uoc)
{
txt += item + "<br />";
}
cmd_response.InnerHtml = "<hr width=\"100%\" noshade/><pre>" + txt + "";
cmd_response.Visible = true;
more.Visible = true;
}
catch (Exception error)
{
xseuB(error.Message);
}
</pre>
If you look at Task Manager and have it show processes for all users, you will see that the programs do run, but they are running under a different session. As a security precaution, the sessions are independent of each other. Programs in one session can not be interacted with by other sessions.
Related
So here's the code:
string filename = #"c:\test.xlsx";
using (XLWorkbook wb = CreateWorkbookInformation())
{
wb.SaveAs(filename);
Email.EmailAsAttachment(filename);
}
File.Delete(filename);
It creates the Workbook information just fine, it saves the file fine, it emails the file fine as an attachment... However, when I try to delete file (after the using statement), it states the "process is in use". There shouldn't be anything keeping the file open?!? What process am I missing that I should close in order to delete the file?
Ahh, nevermind, had nothing to do with ClosedXML, had everything to do with attaching the file to the email and not using a proper usingstatement for the attachment. So the attachment process was keeping the file open.
Thank you so much for posting this answer!!!
I went crazy trying to understand what's my problem!
I did as you suggested and used the proper using statement:
using (MailMessage mail = new MailMessage(senderAdress, emailAdress))
{
SmtpClient client = new SmtpClient();
client.Port = 25;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Host = ConfigurationManager.AppSettings["SMTPHostName"];
if (string.IsNullOrWhiteSpace(client.Host))
{
errorMsg = "ConfigurationManager.AppSettings[\"SMTPHostName\"] not found";
return false;
}
mail.Subject = subject;
mail.IsBodyHtml = isBodyHtml;
mail.Body = body;
if (!string.IsNullOrWhiteSpace(attachmentFullPath))
{
if (File.Exists(attachmentFullPath))
{
System.Net.Mime.ContentType contentType = new System.Net.Mime.ContentType();
contentType.MediaType = System.Net.Mime.MediaTypeNames.Application.Octet;
contentType.Name = Path.GetFileName(attachmentFullPath);
mail.Attachments.Add(new Attachment(attachmentFullPath, contentType));
}
else
{
errorMsg = "Attachment File Doesn't Exist: " + attachmentFullPath;
return false;
}
}
client.Send(mail);
}
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 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();
The asp.net upload control is uploading the file for first time in Ipad but not after that and not even showing any error
The code is as below
protected void UploadThisFile(FileUpload upload)
{
try
{
string folderpath = ConfigurationManager.AppSettings["BTCommDynamic"].ToString() + ConfigurationManager.AppSettings["Attachments"].ToString();
Guid fileguid = Guid.NewGuid();
string filename = fileguid + upload.FileName;
if (upload.HasFile && dtFiles != null)
{
DataRow drFileRow = dtFiles.NewRow();
drFileRow["FileName"] = upload.FileName;
string theFileName = Path.Combine(Server.MapPath(folderpath), filename);
string theFileName1 = Path.Combine(folderpath, filename);
//string theFileName = folderpath;
//to save the file in specified path
upload.SaveAs(theFileName);
drFileRow["FilePath"] = theFileName1;
double Filesize = (upload.FileContent.Length);
if (Filesize > 1024)
{
drFileRow["FileSize"] = (upload.FileContent.Length / 1024).ToString() + " KB";
}
else
{
drFileRow["FileSize"] = (upload.FileContent.Length).ToString() + " Bytes";
}
dtFiles.Rows.Add(drFileRow);
gvAttachment.DataSource = dtFiles;
gvAttachment.DataBind();
}
}
catch (Exception ex)
{
string message = Utility.GetExceptionMessage(ex.GetType().ToString(), ex.Message);
Display_Message(message);
}
}
Do you use firebug? There might be an error on a client side that prevents the work of your functionality.
Do you have any logic on your client side? Some kinda jquery/ajax calls?
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