I am trying to include the text written by enduser in a textfield in an InfopathForm (textfield,multiline,paragraphbreaks and scroll bar if necessary) in an email to the relevant Department.
I always get this error "The name 'remarkmain' does not exist in the current context"
these are some parts of the code i used to define and include in mail:
string remarkmain = xnMyForm.SelectSingleNode("/my:myFields/my:field104", ns).Value;
string BodyAcc = "New Internal Employee " + Titlee + " " + fullname + ".\n Employee is joining " + Comp + " as of " + HireDate + ".\n\n Please view the general information below:\n " + bodyHD + "\n" + bodyED + "\n" + bodyDOB + "\n" + bodytitle + "\n" + bodylast + "\n" + bodyname + "\n" + bodyLang + "\n" + bodyComp + "\n" + bodydep + "\n" + bodyPos + "\n" + Bankacc + "\n" + add + "\n" + CostCtreVZW + "\n" + CostCtreCVBA + "\n\nWork Schedule\n" + WorkMon + "\n" + WorkTue + "\n" + WorkWed + "\n" + WorkThurs + "\n" + WorkFri + "\n" + WorkFDSch + "\n\n" + ContractN + "\n" + EmpN + "\n" + MGR + "\n" + Teamlead +"\n\n" **+ remarkmain** + "\n\n";
I am new to c# and this form i m creating in Infopath ( 2007 )
Have you considered submitting certain values to a form library and using sharepoint workflows via sharepoint designer to send the mail? The sharepoint workflow variable selection and general interface is generally expansive and pleasant and the functionality is extensive.
See to that strign BodyAcc="New Internal Employee+....remarkmain+....; is in remarkmain scope
Use StringBuilder if you have too many string concatinations
StringBuilder BodyAcc = new StringBuilder
BodyAcc.Append(New Internal Employee);
BodyAcc.Append("\n");
BodyAcc.Append(remarkmain);
Related
How can I show the Debug.Log in 2 lines (like adding an enter or <br>) in C#?
I have lots of info to show and compare, yet it is not convenient to read it in one line.
Current result: Debug.Log("Pointer:" + " " + pointerPosX + " " + pointerPosY + " " + "target" + " " + targetPosX + " " + targetPosY);
Expected result:
Pointer: pointerPosX + " " + pointerPosY
Target: targetPosX " " " + targetPosY
P.S. This is my first question in StackOverflow - so, please, let me know if I did something wrong.
Option 1 (\n):
Debug.Log("Pointer:" + " " + pointerPosX + " "
+ pointerPosY + "\n" + "Target:" + " " + targetPosX + " " + targetPosY);
Option 2 (System.Environment.NewLine):
Debug.Log("Pointer:" + " " + pointerPosX + " " + pointerPosY +
System.Environment.NewLine + "Target:" + " " + targetPosX + " " + targetPosY);
Using $ - string interpolation
Option 1:
Debug.Log($"Pointer: {pointerPosX} {pointerPosY}\nTarget: {targetPosX} {targetPosY}");
Option 2:
Debug.Log($"Pointer: {pointerPosX} {pointerPosY}{System.Environment.NewLine}Target: {targetPosX} {targetPosY}");
Difference between "\n" and Environment.NewLine
listBox2.Items.Add(c[n].nume_proprietar + ", " + c[n].nume_catel + ", " + c[n].varsta + " ani , " + c[n].data_vaccin + " " + c[n].tip_vaccin);
Hi, I was wandering if i could insert a line in between " ani , " and c[n].data_vaccin so that my code will display on 2 different lines, obviously with the vallues i insert when i will run the program:
c[n].nume_proprietar ", " c[n].nume_catel ", " c[n].varsta + " ani , " and on another line
c[n].data_vaccin " " c[n].tip_vaccin
Insert Environment.NewLine where you want to breakline. It is environment specific and provides clarity over "\r\n" hence it's preferred to use.
listBox2.Items.Add(c[n].nume_proprietar + ", " + c[n].nume_catel + ", " + c[n].varsta + " ani ," + Environment.NewLine + c[n].data_vaccin + " " + c[n].tip_vaccin);
i would like to make each element of textblockresult visible only when the value is not null.
Intent, ROKEntity, ProcedureName etc are strings that are defined as empty and then receive their value from a json :
string intent = "";
if (!string.IsNullOrEmpty(root.XPathSelectElement("//intent").Value))
{
intent = root.XPathSelectElement("//intent").Value;
}
resultToDisplay = "Action: " + intent
+ Environment.NewLine + "Rok Entity: " + ROKEntity
+ Environment.NewLine + "Rok Entity: " + ROKEntity2
+ Environment.NewLine + "Rok Entity: " + ROKEntity3
+ Environment.NewLine + "Procedure Name: " + ProcedureName
+ Environment.NewLine + "Folder Name: " + FolderName
+ Environment.NewLine + "Task Name: " + TaskName
+ Environment.NewLine + "Worker Name: " + WorkerName
+ Environment.NewLine + "Risk Name: " + RiskName
+ Environment.NewLine + "File Name: " + FileName
+ Environment.NewLine + "Workflow Name: " + WorkflowName
+ Environment.NewLine + "Model Name: " + ModelName
+ Environment.NewLine + "Position Name: " + PositionName
+ Environment.NewLine + "Created by: " + CreatedBy
+ Environment.NewLine + "Modified by: " + ModifiedBy
+ Environment.NewLine + "From: " + From
+ Environment.NewLine + "To: " + To
+ Environment.NewLine + "Display Mode: " + DisplayMode
+ Environment.NewLine + "Data Tracking: " + DataTracking
+ Environment.NewLine + "Details: " + Details
+ Environment.NewLine + "Export Format: " + ExportFormat
+ Environment.NewLine + "Ged Files: " + GedFiles
+ Environment.NewLine + "Ged Folders: " + GedFolders
+ Environment.NewLine + "Map: " + Map
+ Environment.NewLine + "Kpi: " + Kpi
+ Environment.NewLine + "Procedure Type: " + ProcedureType
TextBlockResult.Text = resultToDisplay;
ie i want "Action: " + intent to be visible only when the value of intent is not null nor empty, the same for "Rok Entity: " + ROKEntity and so forth ..
For the moment, i have the following xaml that only allows me to set the visibility of the whole lot to collapsed or hidden or visible:
<TextBlock x:Name="TextBlockResult" Visibility="Collapsed" TextWrapping="Wrap" TextAlignment="Center" FontFamily="Segoe UI" FontSize="16" Foreground="Black"><Run Text="Result"/><InlineUIContainer>
What are the different steps to achieve that please ?
if I understand correctly what you are trying to do, you can just skip the elements with empty or null value. So have a method like
private void AddToDisplay(StringBuilder sb, string title, string value)
{
if (!string.IsNullOrEmpty(value))
{
if (sb.Length > 0)
sb.Append(Environment.NewLine);
sb.Append(title);
sb.Append(value);
}
}
then build your result like
var sb = new StringBuilder();
AddToDisplay(sb, "Action: ", intent);
AddToDisplay(sb, "Rok Entity: ", ROKEntity);
.
.
resultToDisplay = sb.ToString();
that way your results show only non-null non-empty elements and optionally hide the entire TextBlock if resultToDisplay is empty after you are done building it
I've already got the the point where I can save all inputs to a text file but now I would like to create another feature where I can update that file but only through the form itself
private void button_Click(object sender, RoutedEventArgs e)
{
string lb1 = "";
string lb = "";
//Removes listboxtitem object name
ListBoxItem mySelectedItem0 = listBox.SelectedItem as ListBoxItem;
ListBoxItem mySelectedItem1 = listBox1.SelectedItem as ListBoxItem;
if (mySelectedItem0 != null && mySelectedItem1 != null)
{
lb1 = mySelectedItem1.Content.ToString();
lb = mySelectedItem0.Content.ToString();
}
TextWriter saveText = new StreamWriter(#"D:\blah.txt");
saveText.Write("===================================[Receipt]===================================" + "\r\n");
saveText.Write("|Title:" + " " + comboBox.Text + "\r\n");
saveText.Write("|Surname:" + " " + textBox1.Text + "\r\n");
saveText.Write("|Forname:" + " " + textBox2.Text + "\r\n");
saveText.Write("|Passanger[s]:" + " " + textBox6.Text + "\r\n");
saveText.Write("|Group:" + " " + checkBox.IsChecked + " " + "No: " + textBox4.Text + "\r\n");
saveText.Write("|Class:" + " " + comboBox1.Text + "\r\n");
saveText.Write("|Luggage:" + " " + textBox7.Text + "\r\n");
saveText.Write("|Suitcase:" + " " + checkBox1.IsChecked + " " + "No: " +textBox5.Text + "\r\n");
saveText.Write("|Departure On:" + " " + DatePicker.Text + " " + "At:" + " " +comboBox2.Text + "\r\n");
saveText.Write("|Destination From:" + " " + lb + " " + "To:" + " " + lb1 + "\r\n");
saveText.Write("===================================[Receipt]===================================");
saveText.Close();
File.AppendAllText(#"D:\blah.txt", Environment.NewLine);
}
so here it safes all inputs and values as strings into a blah.txt file, how can I now retrieve all information from the file into the form and update it?
You can read the entire content of a text file by using ReadAllText function. Also, you can condense your text construction:
String ticketText = String.Format(#"
===================================[Receipt]====================================
|Title: {0}
|Surname: {1}
|Forname: {2}
...
...
", comboBox.Text, textBox1.Text, textBox2.Text, ...);
saveText.Write(ticketText);
This way of constructing your text is better since everything is done at once and it is easier to read. This will be made even easier when with interpolated strings.
Also I recommend naming your control by their meaning: e.g. txtTitle or TitleText for Title.
In your code you are using 2 different methods to write to a file in one process. You use a StreamWriter to save the receipt. And then static File.AppendAllText to attach an empty line. No need to do that. I think it would be better to generate the message in a separate method and then use the static File.AppendAllText to save everything in one go:
private string GetReceipt()
{
StringBuilder receiptBuilder = new StringBuilder();
receiptBuilder.AppendLine("===================================[Receipt]===================================");
receiptBuilder.AppendLine("|Title:" + " " + comboBox.Text);
receiptBuilder.AppendLine("|Surname:" + " " + textBox1.Text);
receiptBuilder.AppendLine("|Forname:" + " " + textBox2.Text);
receiptBuilder.AppendLine("|Passanger[s]:" + " " + textBox6.Text);
receiptBuilder.AppendLine("|Group:" + " " + checkBox.IsChecked + " " + "No: " + textBox4.Text);
receiptBuilder.AppendLine("|Class:" + " " + comboBox1.Text);
receiptBuilder.AppendLine("|Luggage:" + " " + textBox7.Text);
receiptBuilder.AppendLine("|Suitcase:" + " " + checkBox1.IsChecked + " " + "No: " + textBox5.Text);
receiptBuilder.AppendLine("|Departure On:" + " " + DatePicker.Text + " " + "At:" + " " + comboBox2.Text);
receiptBuilder.AppendLine("|Destination From:" + " " + lb + " " + "To:" + " " + lb1);
receiptBuilder.AppendLine("===================================[Receipt]===================================");
receiptBuilder.AppendLine();
return receiptBuilder.ToString();
}
And then save to the file:
File.AppendAllText(filePath, GetReceipt());
With this small refactoring you can now easily achieve first part of your request: Updating the existing file.
When you need to update the file with new data you simply invoke the GetReceipt() and append the results.
Or if you need the old file to be erased then you can use WriteAllText instead:
File.WriteAllText(filePath, GetReceipt());
Now the reading of the file. Depends what you need. If you just read the text and display it in a text box then it's fairly easy. Just use ReadAllText
myTextBox.Text = File.ReadAllText(filePath);
However if you want to display it in appropriate combo boxes and text boxes then you would have to manually read the file. But if that's the case then I'd encourage you to refactor your code a little bit:
Create a class that holds all the information of the receipt. Each time you want to save your data create a new instance of this class and then serialize it (or save to a database) so it's easy to retrieve specific fields. If you still want to have a nice way to display a receipt you can override the ToString method.
I want to fetch history from browser as soon as a web site is loaded in the browser. It should fetch clients' browser info and save it in a database so that admin may check out the website that is frequently opened and can do survey on the data.
System.Web.HttpBrowserCapabilities browser = Request.Browser;
string s = "Browser Capabilities\n"
+ "Type = " + browser.Type + "\n"
+ "Name = " + browser.Browser + "\n"
+ "Version = " + browser.Version + "\n"
+ "Major Version = " + browser.MajorVersion + "\n"
+ "Minor Version = " + browser.MinorVersion + "\n"
+ "Platform = " + browser.Platform + "\n"
+ "Is Beta = " + browser.Beta + "\n"
+ "Is Crawler = " + browser.Crawler + "\n"
+ "Is AOL = " + browser.AOL + "\n"
+ "Is Win16 = " + browser.Win16 + "\n"
+ "Is Win32 = " + browser.Win32 + "\n"
+ "Supports Frames = " + browser.Frames + "\n"
+ "Supports Tables = " + browser.Tables + "\n"
+ "Supports Cookies = " + browser.Cookies + "\n"
+ "Supports VBScript = " + browser.VBScript + "\n"
+ "Supports JavaScript = " +
browser.EcmaScriptVersion.ToString() + "\n"
+ "Supports Java Applets = " + browser.JavaApplets + "\n"
+ "Supports ActiveX Controls = " + browser.ActiveXControls
+ "\n";
Request.Browser is used to identify the browser info . Using this you can get all info of browser
IIS is already storing this information for you. See: http://msdn.microsoft.com/en-us/library/ms525410%28v=vs.90%29.aspx
To make that data useful you will then need to use a Log Analyzer tool.
Google this term for some options to use: iis log analyzer