|
XmlWriter has a WriteCharEntity method, which converts chars into their element/escaped equivalents, so all I need to do is convert chars not in the range "space" to "tilde" (ie non-latin characters) to determine this
static bool CharacterNeedsEscape(char c)
static bool CharacterNeedsEscape(char c)
{
return c > '~' || c < ' ';
}pre>
Now the text node handling code checks each character in turn, if an escape is not needed the raw character is written, otherwise the <code>WriteCharEntity</code> method is called.
<pre>if (reader.NodeType == XmlNodeType.Text)
{
string startingString = SecurityElement.Escape(reader.Value);
char[] chars = startingString.ToCharArray();
for (int i = 0; i < chars.Length; i++)
{
char c = chars[i];
if (!CharacterNeedsEscape(c))
writer.WriteRaw(chars, i, 1);
else
writer.WriteCharEntity(c);
}
return;
}
The code isn't pretty, but it is fast enough for my purposes....
CCC solved so far: 2 (including a Hard One!)
37!?!! - Randall, Clerks
|
|
|
|
|
Hi!
Perhaps a bit late, but I just needed something similar and found System.Web.HttpUtility.HtmlDecode() and System.Web.HttpUtility.HtmlEncode() , which works just fine in my case.
Perhaps it's useful for you, too.
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
Hi All,
I want to execute and executable file from service using thread. can any body tell me how to execute and exe with 5 minute interval?
I am executing exe from service but it gives me below error in JIT Debugger.
An unhandled exception ('System.InvalidOperationException') occured in Servicemanager.exe[3300]
Thanking You,
Sunil G.
modified on Monday, January 18, 2010 6:49 AM
|
|
|
|
|
Creates a Process object and call Process.Start() every five minutes. Keep in mind that the process object runs the executable with the same user permissions as the user under which the service was installed. I write windows services by creating the core code in a console application, where it's easier to run the debugger and you don't have to hassle with service install/uninstall crap while you're developing.
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
I am using below process to do. but it gives me an error as mentioned earlier.
Process myProcess = new Process();
myProcess.StartInfo.FileName = "G:\\Code\\New Folder\\Monitor\\ServiceManager\\Copy of SVCManager\\ServiceManager\\ServiceManager\\bin\\Release\\ServiceManager.exe";
myProcess.Start();
User is the same.
What is wrong in this?
|
|
|
|
|
Did you look at the inner exception under the debugger?
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
The exe i am executing is a GUI application.
If i run a silent exe it runs properly.
it only gives an error while executing GUI exe.
I dont have depth knowledge.
can u explain how to look into inner exception?
|
|
|
|
|
Sunil G wrote: I dont have depth knowledge.
can u explain how to look into inner exception?
Have a look at Exception.InnerException Property
Thanks
Md. Marufuzzaman
Don't forget to click [Vote] / [Good Answer] on the post(s) that helped you.
I will not say I have failed 1000 times; I will say that I have discovered 1000 ways that can cause failure – Thomas Edison.
|
|
|
|
|
You have to run the service under the debugger
[^].
The only thing I can think of is that a GUI app can't run if there is no user currently logged in.
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
Dear all,
Is there a way to create excel files and write data into excel files using C#, without the installation of MS Excel on the computer?
Thanks in advance.
|
|
|
|
|
There are some components out there (for example XLSReadWriteII.NET) but which versions of excel file format they support (and they are all different) is another matter.
If you are talking about creating the file and writing into it, why not use a CSV file, which is simple to create, simple to amend, and any flavour of excel can read them.
All those who believe in psycho kinesis, raise my hand.
|
|
|
|
|
I can't use csv, it most be xls.
What about using the oledb? with oledb u can also easly read and write excel, bud do you need then MS Excel for this?
|
|
|
|
|
Haven't tried it myself, but this says YES YOU DO[^] which makes sense to me.
Have you considered farming the excel stuff to a server which does have excel loaded (I assume it is the cost that stops you installing on all machines)?
All those who believe in psycho kinesis, raise my hand.
|
|
|
|
|
Use OleDb. it does not require excel to bee installed on the client computer.
However the file must be created first. Then fill it with data.
Also note that there is no UPDATE in using OLEDB/Jet with Excel files. A way around is: delete and add.
|
|
|
|
|
NPOI[^] will do this, open source too
Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Private Void SendMail()
{
MailMessage mMsg = new MailMessage();
SmtpClient sClient = new SmtpClient();
string sHtmlBody = "Test mail ";
AlternateView avHtml = AlternateView.CreateAlternateViewFromString(sHtmlBody);
NetworkCredential crMail = new NetworkCredential();
mMsg.AlternateViews.Add(avHtml);
mMsg.From = new MailAddress("rishi@wi.com","Rishi");
mMsg.To.Add("test@wi.com","Test");
mMsg.Subject = "Test Mail");
//This is my actual local mail server ip, port and username password
//which I've already configured in my outlook and it is working fine.
//-------------------------------
sClient.Host = "192.168.1.7";
sClient.Port = 26;
crMail.UserName = "rishi@wi.com";
crMail.Password = "12345";
//-------------------------------
sClient.UseDefaultCredentials = False;
sClient.Credentials = crMail;
sClient.Send(mMsg);
}
When call this function this shows the error:
"Mail box unavailable. The server response was: No Such User"
There is no issue with this smtp details the same already I've configured in my MS outlook. And also it working fine in VB6 program using CDO.
My requirement is I want to send mails through SMTP which may available in locally or globally.
If anybody have an idea with this pls reply here..
Thanks & Regards,
Rishi
WinCrs
|
|
|
|
|
Try the code snippets given below:
void sendEmail(string strFrom
, string strTo
, string strSubject
, string strBody)
{
MailMessage objMailMessage = new MailMessage();
System.Net.NetworkCredential objSMTPUserInfo =
new System.Net.NetworkCredential();
SmtpClient objSmtpClient = new SmtpClient();
try
{
objMailMessage.From = new MailAddress(strFrom);
objMailMessage.To.Add(new MailAddress(strTo));
objMailMessage.Subject = strSubject;
objMailMessage.Body = strBody;
objSmtpClient = new SmtpClient("172.0.0.1"); objSMTPUserInfo = new System.Net.NetworkCredential
("User name", "Password","Domain");
objSmtpClient.Credentials = objSMTPUserInfo;
objSmtpClient.UseDefaultCredentials = false;
objSmtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
objSmtpClient.Send(objMailMessage);
}
catch (Exception ex)
{ MessageBox.Show (ex.Message.Tostring()); }
finally
{
objMailMessage = null;
objSMTPUserInfo = null;
objSmtpClient = null;
}
}
Thanks
Md. Marufuzzaman
Don't forget to click [Vote] / [Good Answer] on the post(s) that helped you.
I will not say I have failed 1000 times; I will say that I have discovered 1000 ways that can cause failure – Thomas Edison.
|
|
|
|
|
Alright for some reason I can't seem to get this to work. I have tried the following
In form1.cs button click event
I added
Form2 f2 = new form2();
this.AddOwnedForm(f2);
f2.show();
then in form2 I added this in the button event
this.Owner.Controls["bnFindPrice"].enabled = true;
I keep getting object reference not set to instance of object but bnFindPrice is the valid name on form1 of the button I wish to enable.
Thanks for your help.
|
|
|
|
|
The reason is simple: the default access specifiers for controls is not public, so that stuff like this won;t work.
Why not? Because it is very bad practice. It ties the design of the two forms together, so that both must change if one does.
A better idea is to create an event in form two which form one subscribes to. Form two then "throws" the event so say "Changed", and form one handles the implementation.
I.e. Form one knows it has a button, so it handles all thing to do with it, including enable / disable. Form two just knows that the user has done something which form on knows how to handle.
Events aren't difficult to implement:
In form two:
public event EventHandler Changed;
protected virtual void OnChanged(EventArgs e)
{
EventHandler eh = Changed;
if (eh != null)
{
eh(this, e);
}
}
private void DoSomethingToChangeData()
{
OnChanged(null);
}
In form one:
frmChild.Change += new frmChange.ChangeHandler(Changed);
private void Changed(object sender, EventArgs e)
{
}
All those who believe in psycho kinesis, raise my hand.
|
|
|
|
|
Have you checked if owner property is null?
You can have a public property in the form1 for the enabled property of the button. In the second form, you can try this:
this.Parent.BtnEnabled = true;
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
|
|
|
|
|
Use GetControl function to find control by name, e.g.
this.Owner.GetControl("bnFindPrice").enabled = true;
April
Comm100 - Leading Live Chat Software Provider
modified 27-May-14 8:52am.
|
|
|
|
|
|
I want to write some method that will return an array that contain all open / active windows.
How can i do it ?
|
|
|
|
|
You can do that using methods in User32.dll. Here[^] is an example.
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
|
|
|
|
|
Use windows api function EnumWindows, http://msdn.microsoft.com/en-us/library/ms633497(VS.85).aspx
April
Comm100 - Leading Live Chat Software Provider
modified 27-May-14 8:52am.
|
|
|
|