|
how can i execute a DOS command through C# and trigger an event once the command has finished executing?
Example: How can i run chkdsk and then truger an event when it finishes
|
|
|
|
|
You do this as you would any process, except that you need to wait until it's finished executing (and optionally get the return code):
using System;
using System.Diagnostics;
class Test
{
static int Main()
{
int ret = 0;
Process p = Process.Start("notepad.exe", "newfile.txt");
using (p)
{
p.WaitForExit();
ret = p.ExitCode;
Console.WriteLine("Process exited with {0}", ret);
}
return ret;
}
}
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Customer Product-lifecycle Experience
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi there!
I'm trying to implement SMTP client and I'm having a problem:
I'm trying to use remote SMTP (like outlook) so I'm manipulating with MailMessage.Fields:
"http://schemas.microsoft.com/cdo/configuration/sendusing" = 2 - Remote SMTP
"http://schemas.microsoft.com/cdo/configuration/smtpserver" = "smtp.bezeqint.net"; Remote smtp server
"http://schemas.microsoft.com/cdo/configuration/smtpserverport"] = 25 port
and i have all the time the same exception:
"Could not access "CDO.Message" object. Exception has been thrown by the target of an invocation. The SMTP server name is required, and was not in the configuration source".
Please help me!
evgenyus
|
|
|
|
|
Those are only for the Configuration module and won't work on the Message module itself. The MailMessage class in the BCL does not expose the CDO IMessage.Configuration property, however. What you can do is set the static SmtpMail.SmtpServer property, however, before calling SmtpMail.Send .
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Customer Product-lifecycle Experience
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi.
I need to use extended ASCII in my software to cover all the character. Other encoding(Unicode etc) is not an alternative.
My code is as following:
StreamWriter Tex=new StreamWriter(m3uFileName, true, Encoding.ASCII);
I need to be able to use å ä ö etc characters so I need the extended one.
Any suggestions?
|
|
|
|
|
Hi!
I must admit that I've never heard of an "extended ASCII", but there are a few thing you can try nevertheless.
First, you could use Encoding.Defau lt instead of Encoding.ASCII to get the encoding of the current system codepage.
Or, if you know the exact name of the encoding you want, you can use Encoding.GetEncoding(Name) .
Regards,
mav
|
|
|
|
|
ASCII characters are what they are - 7bit characters using codepage 0x4E9F. You can specify a different ANSI code page using Encoding.GetEncoding to specify a code page that contains the character about 127 you want.
The characters above are in the 1250 code page (Western European) so you could use new StreamWriter(m3uFileName, true, Encoding.GetEncoding(1250)) and specify those characters in source as \xe5, \xe4, \xf6, etc.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Customer Product-lifecycle Experience
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Tnx. That was what I needed. I only needed to change 1250 code page into 1252 code page and now my application run fine.
If any want to use the 1252 code page take a look here http://www.kostis.net/charsets/cp1252.htm
|
|
|
|
|
Do anybody know how to plot points on a user form I have created?...
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace WindowsApplication7
{
///
/// Summary description for Form1.
///
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.GroupBox groupBox1;
///
/// Required designer variable.
///
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
///
/// Clean up any resources being used.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(48, 56);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(48, 32);
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(48, 112);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(48, 32);
this.button2.TabIndex = 1;
this.button2.Text = "button2";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(160, 56);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(88, 20);
this.textBox1.TabIndex = 2;
this.textBox1.Text = "textBox1";
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(160, 112);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(88, 20);
this.textBox2.TabIndex = 3;
this.textBox2.Text = "textBox2";
//
// groupBox1
//
this.groupBox1.Location = new System.Drawing.Point(24, 16);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(256, 224);
this.groupBox1.TabIndex = 4;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "groupBox1";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.textBox2,
this.textBox1,
this.button2,
this.button1,
this.groupBox1});
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
}
#endregion
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void button1_Click(object sender, System.EventArgs e)
{
textBox1.Text = Convert.ToString(2*2);
}
private void button2_Click(object sender, System.EventArgs e)
{
textBox2.Text = Convert.ToString(2*2^3+10);
}
private void Form1_Load(object sender, System.EventArgs e)
{
}
}
}
|
|
|
|
|
X and Y are array list.
Bitmap objBitmap;
Graphics objGraphics=Graphics.FromImage(objBitmap);
if(X.count==Y.count)
{
for(int i;i<= X.Count - 1 ;i++)
{
objGraphics.DrawRectangle(new Pen(new SolidBrush(Color.Red)),Convert.ToInt32(X[i]),Convert.ToInt32(Y[i]),2,2);
}
}
U can take help for this example.
|
|
|
|
|
Can anybody fix this problem??
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace WindowsApplication7
{
///
/// Summary description for Form1.
///
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.GroupBox groupBox1;
///
/// Required designer variable.
///
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
///
/// Clean up any resources being used.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(48, 56);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(48, 32);
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(48, 112);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(48, 32);
this.button2.TabIndex = 1;
this.button2.Text = "button2";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(160, 56);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(88, 20);
this.textBox1.TabIndex = 2;
this.textBox1.Text = "textBox1";
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(160, 112);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(88, 20);
this.textBox2.TabIndex = 3;
this.textBox2.Text = "textBox2";
//
// groupBox1
//
this.groupBox1.Location = new System.Drawing.Point(24, 16);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(256, 224);
this.groupBox1.TabIndex = 4;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "groupBox1";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.textBox2,
this.textBox1,
this.button2,
this.button1,
this.groupBox1});
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
}
#endregion
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void button1_Click(object sender, System.EventArgs e)
{
textBox1.Text = Convert.ToString(2*2)+ RAND();
}
private void button2_Click(object sender, System.EventArgs e)
{
textBox2.Text = Convert.ToString(2*2*3^22);
}
private void Form1_Load(object sender, System.EventArgs e)
{
}
// Array of co-ordinates to be plotted
array = [12,23,33,21];
// Plotting loop?
if(X.count==Y.count)
{
for(int i;i<= X.Count - 1 ;i++)
{
objGraphics.DrawRectangle(new Pen(new SolidBrush(Color.Red)),Convert.ToInt32(X[i]),Convert.ToInt32(Y[i]),2,2);
}
}
}
}
|
|
|
|
|
hi
this is part of the code causing the problem:
XmlNodeList l = outputcopy.SelectNodes("//" + tagname);
foreach (XmlNode nod in l)
{
XmlNode parent = nod.ParentNode;
if (parent == null)
{
//break here
}
}
Whenever I try this the last node in the node list appears not to have a parent, even when its not the root node. Whay is this?? I'm totally stumped.....
cheers
|
|
|
|
|
It would be helpful to see the Xml file that you're querying in order to figure out what's wrong...
Picture a huge catholic cathedral. In it there's many people, including a gregorian monk choir. You know, those who sing beautifully. Then they start singing, in latin, as they always do: "Ad hominem..."
-Jörgen Sigvardsson
|
|
|
|
|
Sorry, the xml is:
<xml>
<multiply>
<variable name="x" />
<variabel name="x" />
</multiply>
<symbol>=</symbol>
<multiply>
<number>2</number>
<number>5</number>
</multiply>
</xml>
and tagname is "multiply"
cheers
|
|
|
|
|
|
Hi,
maybe somebody know how i can read IPTC from image file?
Greetings
|
|
|
|
|
Hi everybody!
I have a question to do:
how can i download the HTML code of an internet page, and save it in .txt?
help me plz...
|
|
|
|
|
|
i need the code of an internet page i put in input...all ways are allowed!
|
|
|
|
|
Your browser does that - only it renders it. You can, in your browser, select "File -> Save As" and save it as an HTML page, then open it up in a vanilla (plain) text editor.
If you want to do this programmatically, see the example in the documentation for the HttpWebRequest.GetResponse[^] method. Just save it to a file instead of using the Console .
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Customer Product-lifecycle Experience
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Thank You very much Mr. Heath Stewart!
Exactly i needed!
Thank You again
Enricop
|
|
|
|
|
You can also use RegEx to strip the html tags from the response.
<br />
public string cleanHtmlTags(string inputText)<br />
{<br />
Regex objRejex = new Regex("<([^>]*?)>");<br />
return objRejex.Replace(inputText, "");<br />
}<br />
"If knowledge can create problems, it is not through ignorance that we can solve them." -- Isaac Asimov
|
|
|
|
|
I have a web page with dynamically geneated textboxes and buttons. On click of a button, I want to pull the values from the database and populate the textboxes. I am gettinng confused between the sequence in which the client and server side code gets called. If I call server side first and then client, practically it happens in opp order . For eg-
TableCell tblCell5 = new TableCell();
System.Web.UI.WebControls.Button btn = new System.Web.UI.WebControls.Button();
btn.Text = "Copy";
btn.ID = "btnFetch"+ count.ToString();
counter = count;
btn.CommandArgument = count.ToString();
btn.Command += new CommandEventHandler(RemoveFiles);
btn.Attributes.Add("onclick","setit(" + count + "," + crash +","+ cr +","+ cav+"); ");
tblCell5.Controls.Add(btn);
tblRow.Cells.Add(tblCell5);
Even if I call in this order and set the values of variables in RemoveFiles, the javascript functions gets called first and by that time, the variables are not set.
Also if I try to call javascript from server side function, he javascript function is not yet loaded. For eg-
protected void RemoveFiles(Object sender, CommandEventArgs e)
{
stag = 1;
Response.Write(" alert("+ e.CommandArgument.ToString() +")");
cr = 6;
cav = 9;
hrs=10;
crash = 6;
Response.Write(" setit(' + count + ',' + crash +','+ cr +','+ cav+'); ");
}
Any suggestions?
|
|
|
|
|
I have added a button and a text box onto a form with no methods within the form...I would like to click the button and perform a simple formula of 2*2 and output the answer to the textbox?..just to get me started!
any Ideas Thanks..
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace WindowsApplication2
{
///
/// Summary description for Form1.
///
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.TextBox textBox1;
///
/// Required designer variable.
///
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
///
/// Clean up any resources being used.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.textBox1 = new System.Windows.Forms.TextBox();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(64, 56);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(72, 32);
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// groupBox1
//
this.groupBox1.Controls.AddRange(new System.Windows.Forms.Control[] {
this.textBox1});
this.groupBox1.Location = new System.Drawing.Point(16, 8);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(256, 240);
this.groupBox1.TabIndex = 1;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "groupBox1";
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(56, 120);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(56, 20);
this.textBox1.TabIndex = 0;
this.textBox1.Text = "textBox1";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.button1,
this.groupBox1});
this.Name = "Form1";
this.Text = "Form1";
this.groupBox1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
//Draws the image to fit the ClientRectangle area of the form.
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void button1_Click(object sender, System.EventArgs e)
{
}
}
}
|
|
|
|
|
private void button1_Click(object sender, System.EventArgs e)
{
TextBox1.Text = Convert.ToString(2*2)
}
|
|
|
|
|