Pasting Data into excel file correctly from textbox - c#

foreach (string TempSize in sizeArr)
{
txtResult.Text += store + "\t" + attributeSet + "\t" + configurableAttri + "\t" + type + "\t" + (ID + "_" + TempColour + TempSize) + "\n";
}
I am trying to generate Multiple Rows that i can use to paste into excel file. "\n" doesn't seem to show on the "new line" of the textbox.
I tried manually doing "\n" aka shift+enter and copy paste the 3 rows into excel, Excel place a empty space between each of them, anyway to remove that problem too?
Thanks in advance!

Problem Fixed with "\r\n" instead of "\n" hat's how Windows controls represent newlines

Related

Trying to update a text file

I'm trying to replace a certain line in a .txt file when I click the Update Button
This is what my program looks like
http://i.imgur.com/HKu4bGo.png
This is my code so far
string[] arrLine = File.ReadAllLines("Z:/Daniel/SortedAccounts.txt");
arrLine[accountComboBox.SelectedIndex] = "#1#" + firstNameInfoBox.Text + "#2#" + lastNameInfoBox.Text + "#3#" + emailInfoBox.Text + "#4#" + phoneNumberInfoBox.Text + "#5#EMAIL#6#";
File.WriteAllLines("Z:/Daniel/SortedAccounts.txt", arrLine);
This is what's inside SortedAccounts.txt
#1#Bob#2#Smith#3#Bob#Smith.com#4#5551234567#5#EMAIL#6#
#1#Dan#2#Lastyy#3#Daniel#Lastyy.com#4#5551234567#5#EMAIL#6#
The ComboBox is in the order as the Txt File.
So I get the same Index as the selected item in the ComboBox. And then I want to delete that line and then add a new line that same txt file with the updated information.
My code isn't doing this for some reason though and I can't figure it out
Try this out using List to easily remove an entry at a certain index. Don't forget to reload the combobox data source when the file is updated to avoid index mismatch etc..
List<string> arrLine = File.ReadAllLines("Z:/Daniel/SortedAccounts.txt").ToList();
arrLine.RemoveAt(accountComboBox.SelectedIndex);
string newLine = "#1#" + firstNameInfoBox.Text + "#2#" + lastNameInfoBox.Text + "#3#" + emailInfoBox.Text + "#4#" + phoneNumberInfoBox.Text + "#5#EMAIL#6#";
arrLine.Add(newLine);
File.WriteAllLines("Z:/Daniel/SortedAccounts.txt", arrLine);

c# textbox-as-filename problems

I have been trying to make a program and it saves mechanics invoices. So I have got this far;
oWord.Application.ActiveDocument.SaveAs2("C:/BMW/Invoices/" + Regbox.Text + "/thing.doc");
which saves the word doc in a folder that is specified by the registration of the bike - this works fine. but what I really want is the date to be used as a filename...I couldn't figure that out, so I made a date label and plan on using the text from it as the filename instead (I know, its a long way round...but it works). Anyways, I have tried;
oWord.Application.ActiveDocument.SaveAs2("C:/BMW/Invoices/" + Regbox.Text + "/" + label19.Text + ".doc");
this was an "invalid filename"
oWord.Application.ActiveDocument.SaveAs2("C:/BMW/Invoices/" + Regbox.Text + "/label19.Text.doc");
this saved it as "label19.Text.doc"
oWord.Application.ActiveDocument.SaveAs2("C:/BMW/Invoices/" + Regbox.Text + "/" + label19.Text, ".doc");
This threw the error "(DISP_E_TYPEMISMATCH)"
All I need to do is get label19 text to work as a filename with a .doc extension...or another way of getting the date as a filename
If you need to use current date as file name then you can use:
oWord.Application.ActiveDocument.SaveAs2("C:/BMW/Invoices/" + Regbox.Text + "/" + DateTime.Now.ToString("MM-dd-yyyy") + ".doc")
Generate the file name in an string variable:
string filename = "C:/BMW/Invoices/" + Regbox.Text + "/" + DateTime.Now.ToString("MM-dd-yy");
and then pass it to SaveAs2 method:
oWord.Application.ActiveDocument.SaveAs2(filename, ".doc");

Web Form Cutting Off After Special Character

I have a simple web form where a person can enter into a textbox what kind of project they want. For example, they may type in: Sales & Projection report needs to be fixed.
They then click a submit button and it gets sent off to a third party website that keeps track of our projects.
The problem is, in the example given above, everything gets cut off after the '&' symbol.
it gets sent like this:
String request = "fct=createorcopyproject&guid=" + guid + "&projectname=" + TxtProjectName.Text + "&projectdesc=" + TxtDescription.Text +
"&nexttasknumber=1&budgethours=0&budgetcost=0&estimatedstartdate=" + year + "-" + month + "-" + day + "&estimatedenddate=" + year + "-" + month + "-" + day + "&estimatedhours=0&estimatedexpenses=0&projectpriorityid=" + priorityIndex + "&projectstatusid=NULL&projecttemplate=0&contactname=" + user +
"&defaultestimatedtime=0&defaulttaskstartdate=1&defaulttaskenddate=1&defaulttaskactualdates=2&clientid=" + areaIndex + "&createdefaults=True&languagedefaults=EN&projecttemplateid=0000003&keeptemplatelink=false&copyprojectassignments=True&copyprojectdocuments=True&copyforumtopics=False&copytasks=False&adjusttaskdates=False&copytaskdocuments=False&copytaskassignments=False&markproject=False&format=ds";
Where TxtDescription.Text is where we are getting the cutoff.
Is this something on their end or am I missing something?
Use HttpUtility.UrlEncode method to encode the values you send in an URL (assuming this is an URL)

Parse C# unformated strings in source code then convert to string format

There thousands of calls to log4net in the application which were done with the style of string concatenation instead of using string format like "{0} is greater then {1}".
So we wrote a program that will parse all the .cs files using Regex to find the log4net logging statements. It extracts the code between the parentheses () and then calls a method to reformat it and return the results. Then it rewrites the source code file.
This question relates to the method that reformats the log statement.
It receives an argument of string and returns string.
Here's a sample of the log statements:
"Column " + column + " Seq Cnt: " + sequentialCount + ": Seq Avg: " + (sequentialTotal / sequentialCount)
"Opening file for writing copy protection failed. Retrying.", ex
"for assert " + value.ToString("X")
"ExpirationTime()"
"count = " + count + ", round << " + count + " = " + (round << count)
"Total Diff Bytes = " + (7*count)
(series.Count - i - 1) + " " + series.Time[i] + " O,H,L,C:" + series.Open[i].ToDouble() + "," +
series.High[i].ToDouble() + "," +
series.Low[i].ToDouble() + "," +
series.Close[i].ToDouble()
"Recovered orders from snapshot: \n" + OrderStore.OrdersToString()
Essentially, it seems that the plan should be to use Regex.Replace() with a MatchEvaluator.
What is the correct Regex expression for the Regex.Replace?
These seem to be the requirements:
Essentially find each interruption in the string "\s*+\s*(.*)\s+" (over simplified).
Replace each match with a token of the form {0} in the string and then put the specified value as an argument to the method.
Debug methods of the form log.Debug("message",ex) which have a reference to an exception must be identified and skipped.
Of course, the code will switch the calls to DebugFormat() InfoFormat() and so on.
The problem with the above Regex is that it matches this as the first match:
" + column + " Seq Cnt: " + sequentialCount + "
instead of:
" + column + "
I can't simply use ([^"]) instead of (.) or ([^+]*) since some of the values have additional plus or use quotes as arguments to methods.
So it needs some way to say match all characters except if the match the pattern \s+\s" which means plus sign followed by a quote separated by optional white space.
You can make the quantifier lazy. For example:
"\s*\+\s*(\S.*?)\s*\+\s*"

adding space and new line in html editor asp.net ajax

I want to insert blank characters in a string move to next line and align right in Html editor ajax control and it should be hardcoded in my below code .
My code is
Editor1.Content = "No. J/" + DropDownList3.SelectedItem + "-" + TextBox1.Text + "-" + tyear + "/" + " " + "/" + year + DateTime.Now.Day+"/"+DateTime.Now.Month+"/"+DateTime.Now.Year;
What i want is
i want 5 blank spaces after
....+ tyear + "/" + "....
Move to next/new line after
....." + "/" + year +....
Apply Align left to this entire
content
To add blank spaces to the keyword. Normal blank spaces will be ignored as whitespace by the HTML parser.

Categories