I have encountered a problem that others seem to have also encountered, but their solutions don't seem to work for me:
Using \x01 send the message as "ACTION wave" with nothing else.
The solutions I've found but haven't worked are:
Using \001: message is interpret as "01ACTION waves" but I get a "No
text to send" error.
Using \0001: same issue. Using \u0001: only
sends "ACTION waves" but prints an unknown symbol before action.
Apparently the issue is the '\0' part where it interprets it as an escape character, is there a way to avoid this? I have tried the following three methods already:
writer.WriteLine("PRIVMSG " + CHANNEL + " :" + CONTROL + "ACTION " +
message.Remove(0, 3) + CONTROL);
writer.WriteLine("PRIVMSG " + CHANNEL + " :" + "\u0001" + "ACTION " +
message.Remove(0, 3) + "\u0001");
writer.Write(string.Format("PRIVMSG {0} :{1} ACTION {2}{1}", CHANNEL,
CONTROL, message.Remove(0,3)));
Where CONTROL = either one of the values before mentioned.
A better more simple way will be using hex character \x01.
Code:
writer.WriteLine("PRIVMSG {0} :{1}ACTION {2}{1}", CHANNEL, '\x01', message.Remove(0, 3))
Related
I'm tasked with converting some older VB.net code to C#. Been slowly chipping away at the errors -went from about 100, down now to ~10. The first vb.net code that needs to be converted is:
Try
My.Computer.FileSystem.CopyFile(strFile, strExportPath + "\" + strFileName(0), FileIO.UIOption.OnlyErrorDialogs, FileIO.UICancelOption.DoNothing)
intFilesCopied += 1
My.Computer.FileSystem.MoveFile(strFile, _strPath + "Data\Backup\" + strFileName(0), FileIO.UIOption.OnlyErrorDialogs, FileIO.UICancelOption.DoNothing)
intFilesMoved += 1
Catch ex As Exception
My.Application.Log.WriteException(ex, TraceEventType.Error, "ExportDataToolStripMenuItem_Click")
End Try
My C# attempt is as follows:
try
{
File.Copy(strFile, strExportPath + #"\" + strFileName[0], UIOption.OnlyErrorDialogs,
FileIO.UICancelOption.DoNothing);
intFilesCopied += 1;
File.Move(strFile, _strPath + #"Data\Backup\" + strFileName[0],
UIOption.OnlyErrorDialogs, UICancelOption.DoNothing);
intFilesMoved += 1;
}
catch (Exception ex)
{
Application.Log.WriteException(ex, TraceEventType.Error, "ExportDataToolStripMenuItem_Click");
}
The next piece of VB.NET is the catch portion of the try-catch clauses.
My.Application.Log.WriteException(ex, TraceEventType.Error, "Could not write record to data file " + _strActiveFileName + Environment.NewLine + "Record Data: " + strRecordText);
And for the life of me, cannot find the C#-equivalent for this.
I've tried adding the Microsoft.VisualBasic dll/reference/namespace, but that doesn't work either. Tried to google the C#-equivalent, but couldn't find anything.
The next piece of VB.NET is the catch portion of the try-catch
clauses.
My.Application.Log.WriteException(ex, TraceEventType.Error, "Could not
write record to data file " + _strActiveFileName + Environment.NewLine
+ "Record Data: " + strRecordText);
And for the life of me, cannot find the C#-equivalent for this.
This can be converted by (with reference to Microsoft.VisualBasic.dll):
Microsoft.VisualBasic.ApplicationServices.ApplicationBase MyApplication = new Microsoft.VisualBasic.ApplicationServices.ApplicationBase();
then :
MyApplication.Log.WriteException(ex, TraceEventType.Error, "ExportDataToolStripMenuItem_Click");
And you can check the log file with :
System.Windows.Forms.MessageBox.Show(MyApplication.Log.DefaultFileLogWriter.FullLogFileName);
(just tested on Windows 10)
I'm trying to generate an email with some basic formatting based on labels in a FormView. I'm going the route of Process.Start("mailto:... instead of System.Net.Mail so the email opens up in the default email client to give the user a chance to edit To: CC: etc without making a new form just to handle that. I've got the following code-behind to handle an "Email Form" button for emailing the URL of the webform.
protected void fvBF_ItemCommand(object sender, FormViewCommandEventArgs e)
{
if (e.CommandName == "Email")
{
Label lblBFID = (Label)fvBookingForm.FindControl("lblBFID");
Label lblProjectID = (Label)fvBookingForm.FindControl("lblProjectNum");
Label lblProjectName = (Label)fvBookingForm.FindControl("lblProjectName");
Label lblReleaseName = (Label)fvBookingForm.FindControl("lblReleaseName");
Label lblPMName = (Label)fvBookingForm.FindControl("lblPM");
String strReleaseName = String.IsNullOrEmpty(lblReleaseName.Text) ? "[Description]" : lblReleaseName.Text;
String pmFirst = lblPMName.Text.ToString().Split()[0];
String pmLast = lblPMName.Text.ToString().Split()[1];
String strSubject = "BF " + lblBFID.Text + " - " + lblProjectName.Text + " - Release " + strReleaseName;
String strBody = "A Booking Form for Project #"+ lblProjectID.Text + " - " + lblProjectName.Text +
" - Release " + strReleaseName + " has been created or modified. \n\n" + Request.Url.ToString();
Process.Start("mailto:" + pmFirst + "." + pmLast + "#company.com?subject=" +
HttpUtility.HtmlAttributeEncode(strSubject) + "&body=" +
HttpUtility.HtmlAttributeEncode(strBody).Replace("\n", Environment.NewLine));
}
}
However, when the email is generated, there are no line breaks in the body between the "A Booking Form...." sentence and the URL. I've tried putting Environment.NewLine directly in the string.
...created or modified. " + Environment.Newline + Environment.NewLine + Request.Url.ToString();
Which basically gives me the same results. I've tried replacing the \n with <br /> which doesn't add the line break and for some reason, doesn't display the URL either. I can only guess that the problem has to do with the HtmlAttributeEncode() and getting it to parse the NewLine properly. Is there something I'm missing here?
You might want to try .Replace("\r\n", "<br />") on the body after you have done your encoding of the body.
You should probably use StringBuilder here instead of String.
You can then do the following:
StringBuilder builder = new StringBuilder();
builder.AppendLine(string.Format("A Booking Form for Project #{0} - {1}",lblProjectID.Text, lblProjectName.Text));
builder.AppendLine(string.Format(" - Release {0} has been created or modified.", strReleaseName));
builder.AppendLine();
builder.AppendLine(Request.Url.ToString());
String strBody = builder.ToString();
You can also include (char)10 and (char)13 in your string creation. e.g.:
string.Format("First Line{0}{1}Second Line", (char)10, (char)13);
Model.Message = "my message \n second message";
then add this style to string tag style="white-space: pre-line;"
example <h3 style="white-space: pre-line;">#Model.Message</h3>
I am trying to send an email to a supervisor when a work order is created
if(TextBox9.Text=="Quality"&&affectedrows==true)
{
boolisLocal=HttpContext.Current.Request.IsLocal;
if(isLocal==true)
{
System.Net.Mail.MailMessagenn=newSystem.Net.Mail.MailMessage();
nn.From=newSystem.Net.Mail.MailAddress("no_reply_workorder#mover.com");//whosend
nn.To.Add(newSystem.Net.Mail.MailAddress("someone.something#mover.com"));
nn.Subject="WorkOrdersTypeQuality";
HttpFileCollectionuploadFiles=Request.Files;
for(inti=0;i<uploadFiles.Count;i++)
{
HttpPostedFileuserpostedfils=uploadFiles[i];
try
{
if(userpostedfils.ContentLength>0)
{
nn.Attachments.Add(newAttachment(userpostedfils.InputStream,Path.GetFileName(userpostedfils.FileName)));
}
}
catch
{
Labelstatusmessage=(Label)DetailsView1.FindControl("lblmessage");
statusmessage.Text="UploadFailedPleaseContactDeveloper";
}
}
nn.Body="DONOTREPLYTOTHISEMAIL"+"<br><br/>"+"WorkOrderNumber"+": "+
""+TextBox13.Text+""+"<-ClickontheWorkOrderNumberForReport"+"<br><br/>"+"WorkOrderNumber"+
": "+""+TextBox13.Text+""+"<-ClickontheWorkOrderNumberToEnterData"+"<br><br/>"+"Requestor"+
": "+TextBoxRequestor.Text+"<br><br/>"+"Date"+": "+
TextBoxDate.Text+"<br><br/>"+"Department"+": "+
TextBox14.Text+"<br><br/>"+"CompletionDate"+": "+
TextBoxCompletionDate.Text+"<br><br/>"+"MachineDescription"+
": "+TextBoxMachineDescription.Text+"<br><br/>"+
"MachineLocation"+": "+TextBoxMachineLocation.Text+
"<br><br/>"+"WorkRequired"+": "+TextBoxWorkRequired.Text+
"<br><br/>"+"Status"+": "+TextBoxStatus.Text;
nn.IsBodyHtml=true;
System.Net.Mail.SmtpClientclient=newSystem.Net.Mail.SmtpClient();
client.Host=ConfigurationManager.AppSettings["smtpServer"];
captureuseremail();
}
}
in the body of the mail I am sending an link to the workorder that just got created, "http://server01/WorkOrder/QualityReport.aspx?WorkOrderNum="TextBox13.Text+"\">" I am working on four different plants so I need to deploy each project to 4 servers and change the link above to server02, server03, and server04 and there are 3 types of workorders so I was thinking of storing each link into a key in web.config:
<add key ="safetylink" value="http://server01/WorkOrderTool/SafetyReport.aspx?WorkOrderNum="/>
Get the value from web.config and store as string and use it in the email I am not sure how to do that:
string safetylink = ConfigurationManager.AppSettings["safetylink"];
mm.Body = "DO NOT REPLY TO THIS EMAIL" + "<br><br/>" + "WorkOrderNumber" + ": " + "<a href=\"safetylink" + TextBox13.Text + "\">"
but that does not work, by doing the above I hope to simple deploy one web application to 4 servers and go into each ones web.config and change the name of the server instead of find and replace.
Thank You in advance coders
thanks to SamIam anytime you want to sent a string as a hyperlink in the body of an email:
use "<a href=\"" + yourstringname"
I am trying to make to create a .cmd file with this code into it: call .\CopyToTarget.cmd w60 glb "C:\Users\oma\me\trunk-r664\USB-map". I am creating this code ~5 times.
But since \trunk-r664\ is already in use it seems like I cannot write: #"\trunk-r664\USB-map" into the .cmd file for some reason. Does anyone know how to fix it? It keeps getting me the error: UnauthorizedAccesExpection was unhandled, ccess to the path 'C:\Users\me\Desktop\trunk-r664\USB-map' is denied.
using (StreamWriter sw = File.CreateText(Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
+ "\\trunk-r664\\trunk\\cmd\\custom\\RunAll.cmd"))
{
for (int j=0;j<installeerlijst64.Count;j++)
{
sw.WriteLine("call .\\CopyToTarget.cmd " + installeerlijst64[j] + " glb" +
File.CreateText(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + #"\trunk-r664\USB-map"));
}
}
I tried this too, but it tells me I am using an illegal character:
"\""+File.CreateText(Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
+ #"\trunk-r664\USB-map" + "\""));
File.CreateText will create a new file. First time when for loop execute, it will create and open the file USB-map and hold the handle of that file. During second iteration of for loop, it will try to do the same thing. Hence, already in use error.
Remove File.CreateText and you will get the desired result.
sw.WriteLine("call .\\CopyToTarget.cmd " + installeerlijst64[j] + " glb " + "\"" +
Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + #"\trunk-r664\USB-map" + "\"");
I have a form that the users for my website will fill out. Once they click submit the information they filled out is supposed to be sent to my email. For some reason the information they fill out is not being sent. I am posting the code below. For a while it was working, but I must have changed something simple when I was trying to get other parts of the code to work and now I can't figure it out.
protected void Submit_Click1(object sender, EventArgs e)
{
try
{
string strMessage = "Bug Name: " + txtBugName.Text.Trim()
+ "<br/>" + "Module Name: " + ddlModule.SelectedValue
+ "<br/>" + "Page Name: " + ddlPage.SelectedValue
+ "<br/>" + "Description: " + txtComments.Text.Trim()
+ "<br/>" + "Email is" + " " + txtemail.Text.Trim()
+ "<br/>" + "The request was sent at" +
SendMessage(ConfigurationManager.AppSettings["EmailAddrTo"],
ConfigurationManager.AppSettings["EmailAddrFrom"],
txtBugName.Text.Trim(),
strMessage, "", "");
}
catch
{
}
}
As you can see I have this code pulling the information they fill out and then also I am formatting it for the email that will be sent to myself. But now I just get a blank email or actually the subject line will have something, but the email will be blank.
Also at the bottom of the code you can see i put this email was sent at + dandt I am trying to have the date and time sent in that part is there any code I can just put there to send the date and time the email was sent at? Like is there any syntax specifically just for date and time?
Thank you all
You're swallowing the exception. Remove the try/catch to see any errors that may occur as you change your code; only apply exception handling after testing.
Verify your method signature (params) here because that's where the mistake lies:
UPDATE:
You need to pass the parameters in the following order (read the link below):
public void Send(
string from,
string to,
string subject,
string body
)
SmtpClient.Send Method (String, String, String, String)
Your wrote the following, with extra strings snipped:
string strMessage = "..." + ... + SendMessage(..., strMessage, ...);
You're calling SendMessage() before assigning strMessage.