|
George_George wrote: I am wondering whether there are any built-in log component in C# so that I can utilize directly other than write from scratch?
There are classes that allow you to write to the event log. However, if you want a proper log component you'll have to look for things like log4net or the Microsoft Enterprise Library Logging Application Block.
|
|
|
|
|
Seconded on log4net. Very easy to get up and running.... or logging.
|
|
|
|
|
Thanks Mark,
Microsoft has no built-in Log function?
regards,
George
|
|
|
|
|
Well we went with log4net because it had some features we wanted to use in the future. Firstly we had it logging to SQL server, but then we got it to shoot out UDP packets for high priority log entries to a remote console (in another country)!
You can log to the windows event log using (it think) classes in System.Diagnostics, thats quite easy to get working.
|
|
|
|
|
Thanks Mark,
What means *shoot out UDP packets for high priority log entries*? Why using UDP for high priority? What packages do you use for normal priority log -- TCP?
regards,
George
|
|
|
|
|
Ah sorry to be confusing. We log everything to SQL server. High priority messages (non sensitive) get stuffed in a UDP packet (theres a UDP log appender for log4net) and sent to my laptop. I run a program on my laptop that pops up - so if anything serious is going on then I know about it.
As for UDP/TCP... UDP is a little more convenient than TCP, as there is no connection setup. You can just stick a packet with a destination address out on the wire and it will (probably) get to the destination
|
|
|
|
|
Hi Mark,
You mean UDP transmission is faster then TCP, right?
regards,
George
|
|
|
|
|
Thanks Colin,
You mean Microsoft .Net has no built-in log function? What is *Microsoft Enterprise Library Logging Application Block*? Is it easy to use? I only want to write to local file, no complex function needed.
regards,
George
|
|
|
|
|
Here's[^] a simple-minded logger that may meet your initial needs.
/ravi
|
|
|
|
|
Thanks Ravi,
Seems it does not provide function to limit the size of log?
regards,
George
|
|
|
|
|
From the help file of ConnectionState enum type:
Broken The connection to the data source is broken. This can occur only after the connection has been opened. A connection in this state may be closed and then re-opened. (This value is reserved for future versions of the product.) <br />
Closed The connection is closed. <br />
Connecting The connection object is connecting to the data source. (This value is reserved for future versions of the product.) <br />
Executing The connection object is executing a command. (This value is reserved for future versions of the product.) <br />
Fetching The connection object is retrieving data. (This value is reserved for future versions of the product.) <br />
Open The connection is open.
I'm using .NET 2.0. Does this mean that the values "Broken", "Connecting", "Executing" and "Fetching" are useless?
Does .NET 3.0 or 3.5 changed this?
Thanks.
|
|
|
|
|
in a text box which accepts only numbers ,when the user tries to input a alphabatical character ,i want to ignore the key stroke ?
|
|
|
|
|
Why not use a MaskedTextBox?
|
|
|
|
|
You can set up an event handler for keypress event to check whether the key that was pressed is digit or not. Depending on that you can ignore the key if it isn't a digit or a backspace
|
|
|
|
|
Hi
I want to transmit a live video from server to multi clients using UDP, I m working in C# and I've captured the video from WebCam. So please tell me the steps to be follow to accomplish this task.OR if u have any tutorials or links related to my task plz Notify me.
Regards.
Shanzay
|
|
|
|
|
i have text column in the database(access).the column contains a image path information.all i have to do is to show the image in crystal reports .if i use the ole object then it is coming fine in the crystal reports but i am stuck at showing the pic when showing the image in the crystal reports while accessing the path from the database.
Soniagupta1@yahoo.co.in
|
|
|
|
|
Sonia Gupta wrote: he column contains a image path information.all i have to do is to show the image in crystal reports
Showing dynamic images in crystal reports would be a hectic problem. Passing image name and showing it over there is not possible. One option would be storing image in database as BLOB. Crystal reports having capability to render this BLOB data. But for this you need to switch your DB to SQL Server.
|
|
|
|
|
how can i retrieve the images from the database to my form in c#? the images are in the ole type column
Soniagupta1@yahoo.co.in
|
|
|
|
|
My application will generate a word document as report. The application created Word Application and Document objects.
When users click on Close or the "X" icon on the up right corner. The application will intercept word DocumentBeforeCloseEvent, to ask users Save, No or Cancel to the document changes. Everything works fine except when users click on "Cancel", Word still displays it's own Dialog for users to select Yes, No or Cancel for saving the document changes.
Is there anyway to prevent this Word dialog because my application already process uses decision?
Here is part of the code:
Word_DocumentBeforeClose is used to process users decision.
The last part of If in else is to process when Cancel is clicked.
namespace HandleWordEvnts
{
public partial class Form1 : Form
{
#region properties
Word.ApplicationClass wordApp;
Word.Document wordDoc;
string docName;
#endregion properties
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
//===== Create a new document in Word ==============
// Create an instance of Word and make it visible.
wordApp = new Word.ApplicationClass();
wordApp.Visible = true;
// Local declarations.
Object oMissing = System.Reflection.Missing.Value;
// Add a new document.
wordDoc = wordApp.Documents.Add(ref oMissing, ref oMissing,
ref oMissing, ref oMissing); // Clean document
// Add text to the new document.
wordDoc.Content.Text = "Handle Events for Microsoft Word Using C#.";
docName = wordDoc.Name;
//============ Set up the event handlers ===============
wordApp.DocumentBeforeClose +=
new Word.ApplicationEvents2_DocumentBeforeCloseEventHandler(
Word_DocumentBeforeClose);
}
// The event handlers.
private DialogResult showSaveFileDlg(ref string fileName, ref string filePath)
{
DialogResult dlgRes = DialogResult.None;
object locker = new object();
Thread.Sleep(1000); //time needed for dialog to display
lock (locker)
{
saveFileDialog1.Title = "App Save As";
saveFileDialog1.FileName = filePath != "" ? (filePath + "\\" + fileName) : fileName; //init full name
saveFileDialog1.InitialDirectory = filePath;
saveFileDialog1.Filter = "Word Document (*.doc)|*.doc| Plain Text (*.txt)|*.txt|All files (*.*)|*.*";
saveFileDialog1.FilterIndex = 1;
saveFileDialog1.RestoreDirectory = true;
dlgRes = saveFileDialog1.ShowDialog();
if (dlgRes == DialogResult.Cancel) return dlgRes;
fileName = saveFileDialog1.FileName.Substring(saveFileDialog1.FileName.LastIndexOf("\\") + 1);
filePath = saveFileDialog1.FileName.Substring(0, saveFileDialog1.FileName.LastIndexOf("\\"));
return dlgRes;
}
}
private void Word_DocumentBeforeClose(Word.Document doc, ref bool Cancel)
{
docName = doc.Name;
string fileName = doc.Name;
string filePath = doc.Path;
// ask user to save or not
DialogResult dlgRes = DialogResult.None;
AskSaveCnanges askSave = new AskSaveCnanges();
askSave.setTxtBox1 = filePath != "" ? (filePath + "\\" + fileName) : fileName;
askSave.setTxtBox1Readonly = true;
askSave.ShowDialog();
if (askSave.DlgRes == DialogResult.Yes) //user agrees to save
{
Thread showWordDlg = new Thread(delegate() { dlgRes = showSaveFileDlg(ref fileName, ref filePath); });
showWordDlg.SetApartmentState(ApartmentState.STA);
showWordDlg.Name = "DocClose";
showWordDlg.Start();
showWordDlg.Join();
if (dlgRes == DialogResult.OK) //user agrees to save
{
MessageBox.Show("DocumentBeforeClose ( Saved " + doc.Name + " )","APP");
//Save the file, use default values except for filename
object ofileName = filePath + "\\" + fileName;
object optional = Missing.Value;
try
{
doc.SaveAs(ref ofileName, ref optional, ref optional, ref optional,
ref optional, ref optional, ref optional,
ref optional, ref optional, ref optional, ref optional);
//doc.Save();
doc.Saved = true;
object saveChanges = true;
object originalFormat = Missing.Value;
object routeDocument = Missing.Value;
wordApp.Quit(ref saveChanges, ref originalFormat, ref routeDocument);
}
catch (COMException e)
{
MessageBox.Show(e.Message,"ApP.DocumentBeforeClose");
}
//saveAs = false;
//Cancel = true;
}
}
else if (askSave.DlgRes == DialogResult.No)
{
MessageBox.Show("DocumentBeforeClose ( Not Saved " + doc.Name + " )","APP");
Cancel = true;
object saveChanges = false;
object originalFormat = Missing.Value;
object routeDocument = Missing.Value;
doc.Close(ref saveChanges, ref originalFormat, ref routeDocument);
wordApp.Quit(ref saveChanges, ref originalFormat, ref routeDocument);
}
else
{
MessageBox.Show("DocumentBeforeClose ( Canceled " + doc.Name + " )","APP");
//When users cilck on Cancel button.
// Cancel is set to true but Word still displays it's own dialog.
Cancel = true;
doc.Saved = false;
wordApp.Activate();
Thread.Sleep(5000);
//send key does not work either
SendKeys.SendWait("{RIGHT}{RIGHT}{ENTER}");
}
}
}
|
|
|
|
|
Hey,
I'm having some problems starting a command-line program using Process.Start(). I pass it the filename and arguments, and it runs the program, but instantly crashes and a "Program has stopped working" error comes up. I can't figure out what is wrong. The program runs fine from the command line and when I use a shortcut, and Process.Start() runs other programs fine. Can anyone tell me what is wrong?
For reference, I am running this in Vista.
|
|
|
|
|
As per my experience you have problem in passing arguments.
Try without argument passing, and change the way to pass arguments.
Hope you will find solution.
I have tried to give hint to your problem.
Best Regards,
Chetan Patel
|
|
|
|
|
Well classical problems like this are solved by using unmanaged code equivilant to the System.Diagnostics namespace from the win32 api.
(Hint: search MSDN)
Hope this helps!!;)
To follow the path, Walk with the MASTER, See through the MASTER, Be the MASTER!
|
|
|
|
|
I inherited a program that takes data from a csv file and inserts it into a database.
The data is in the following format:
8/20/2007 12:14:21 PM,HDFM,"Nick Yockell","Nate Wittrock",239-850-3931,239-850-2514,"Used 2004 Harley Davidson ","bought bike
CUSTOMER WANTS TO BRING HIS YAMAHA R6 IN TO TRADE AND SEE HOW MUCH PAYMENTS WOULD BE.
",Deliver,aa32ed31-f0c8-4f43-a7d4-830d9f29edcd
For some reason the function that saves the data to the database is having a problem with the customer phone number (5th column).
The database column is a varchar(50) - the same as the customer business phone number.
If the customer home phone contains anything other that digits it cannot be saved to the database.
However, the customer business phone can contain anything and gets saved just fine.
Is there anything in the two functions that could be causing this ?
private void ProcessFile(string filename, string vendor)
{
string path = string.Empty;
string LoggingDate = DateTime.Now.ToString();
switch (vendor.ToLower())
{
case "vpulse":
path = DIRECTORYPATHVPULSE;
break;
case "calllogpro":
path = DIRECTORYPATHCALLLOGPRO;
break;
}
try
{
OleDbConnection ExcelConnection = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+path+"\\"+";Extended Properties=\"Text;HDR=No;FMT=Delimited()\"");
//OleDbConnection ExcelConnection = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+this.txtSource.Text+"\\"+";Extended Properties=\"Text;HDR=No;\"");
OleDbCommand ExcelCommand = new OleDbCommand(@"SELECT * FROM "+filename,ExcelConnection);
OleDbDataAdapter ExcelAdapter = new OleDbDataAdapter(ExcelCommand);
ExcelConnection.Open();
DataSet ExcelDataSet = new DataSet();
ExcelAdapter.Fill(ExcelDataSet);
ExcelConnection.Close();
//Process File
ProcessFileRecords(ExcelDataSet, vendor.ToLower());
//Email Copy to Alliance Group
this.EmailFile(path, filename, vendor);
}
catch (Exception exc)
{
string errorText = exc.ToString();
System.Diagnostics.EventLog.WriteEntry("Alliance Level 2 DataRetreiver", errorText);
}
finally
{
//Archive Copy
this.ArchiveFile(path, filename);
}
}
private void ProcessFileRecordVPulse(object[] record)
{
string logdate = string.Empty;
string dealership = string.Empty;
string salesperson = string.Empty;
string customername = string.Empty;
string homephone = string.Empty;
string businessphone = string.Empty;
string product = string.Empty;
string comments = string.Empty;
string sellstage = string.Empty;
string vpulsecalltaskid = string.Empty;
string LoggingDate = DateTime.Now.ToString();
try
{
logdate = Convert.ToDateTime(record[0]).ToShortDateString();
dealership = record[1].ToString();
salesperson = record[2].ToString();
customername = record[3].ToString();
try
{
homephone = record[4].ToString();
//homephone.Replace("-", "");
}
catch
{
homephone = "Bad format";
}
businessphone = record[5].ToString();
product = record[6].ToString();
comments = record[7].ToString().Replace("
", " ");
//***Get Sales Stage
sellstage = record[8].ToString();
switch(sellstage.ToLower())
{
case "greet":
sellstage = "1";
break;
case "probe":
sellstage = "2";
break;
case "identify machine":
sellstage = "3";
break;
case "presentation":
sellstage = "4";
break;
case "sit down":
sellstage = "5";
break;
case "write up":
sellstage = "6";
break;
case "close the deal":
sellstage = "7";
break;
case "finance":
sellstage = "8";
break;
case "deliver":
sellstage = "9";
break;
default:
if (sellstage.ToLower().IndexOf("service") == -1 && sellstage.ToLower().IndexOf("parts") == -1)
sellstage = "1";
else
sellstage = sellstage;
break;
}
//***Get Sales Stage
vpulsecalltaskid = record[9].ToString();
//Import lead record
SqlCommand command = this.GetCommand();
command.CommandText = @"INSERT INTO CallLogs
(LogDate,
VPulseCallTaskId,
CallLogTypeId,
DealerId,
SalesPerson,
CustomerName,
CustomerHomePhone,
CustomerBusinessPhone,
Product,
Comments,
SaleStage,
LogProcessFlag,
CSI14Days,
CSI17Months,
CSI14DaysProcessFlag,
CSI17MonthsProcessFlag)
VALUES
(@LogDate,
@VPulseCallTaskId,
@CallLogTypeId,
@DealerId,
@SalesPerson,
@CustomerName,
@CustomerHomePhone,
@CustomerBusinessPhone,
@Product,
@Comments,
@SaleStage,
@LogProcessFlag,
@CSI14Days,
@CSI17Months,
@CSI14DaysProcessFlag,
@CSI17MonthsProcessFlag)";
command.Parameters.Add("@LogDate", logdate);
command.Parameters.Add("@VPulseCallTaskId", vpulsecalltaskid);
if ((sellstage.ToLower().IndexOf("service") == -1)&&(sellstage.ToLower().IndexOf("parts") == -1))
{
command.Parameters.Add("@CallLogTypeId", "1");
}
else
{
if (sellstage.ToLower().IndexOf("service") != -1)
{
command.Parameters.Add("@CallLogTypeId", "1"); //Service (4)
dealership = dealership+"_SERVICE";
sellstage = "1";
}
else if (sellstage.ToLower().IndexOf("parts") != -1)
{
command.Parameters.Add("@CallLogTypeId", "1"); //Parts (3)
dealership = dealership+"_PARTS";
sellstage = "1";
}
}
command.Parameters.Add("@DealerId", dealership);
command.Parameters.Add("@SalesPerson", salesperson);
command.Parameters.Add("@CustomerName", customername);
command.Parameters.Add("@CustomerHomePhone", homephone);
command.Parameters.Add("@CustomerBusinessPhone", businessphone);
command.Parameters.Add("@Product", product);
command.Parameters.Add("@Comments", comments);
command.Parameters.Add("@SaleStage", sellstage);
command.Parameters.Add("@LogProcessFlag", false);
command.Parameters.Add("@CSI14Days", Convert.ToDateTime(logdate).AddDays(14).ToString());
command.Parameters.Add("@CSI17Months", Convert.ToDateTime(logdate).AddMonths(17).ToString());
command.Parameters.Add("@CSI14DaysProcessFlag", false);
command.Parameters.Add("@CSI17MonthsProcessFlag", false);
command.ExecuteNonQuery();
this.DisposeCommand(command);
}
catch (Exception exc)
{
string errorText = exc.ToString();
System.Diagnostics.EventLog.WriteEntry("Alliance Level 2 DataRetreiver", errorText);
}
|
|
|
|
|
I had read your code, i think it works can you give me the error.
In above code there is no error.
Best Regards,
Chetan Patel
|
|
|
|
|
If the customer home phone contains anything other that digits it cannot be saved to the database.
Thanks,
Nathan
|
|
|
|
|