|
The code I posted only reads the first line, and will throw an error if the file is empty
To process the whole file you need the loop. You need to decide how you are going to handle it. The way I see it you have a few realistic options:
- Create a list of errors and add to it in the loop.
- Only register the first error and continue processing.
- Break out of the loop if an error is found.
Which of these apply?
Dalek Dave: There are many words that some find offensive, Homosexuality, Alcoholism, Religion, Visual Basic, Manchester United, Butter.
Pete o'Hanlon: If it wasn't insulting tools, I'd say you were dumber than a bag of spanners.
|
|
|
|
|
Cool bro I have figured it out check below:
manager = new data_manager();
HttpPostedFile myFile = files.PostedFile;
string strFilename = Path.GetFileName(myFile.FileName);
if (strFilename != "")
{
string[] lines = File.ReadAllLines(strFilename);
for (int b = 0; b < lines.Length; b++)
{
string[] fragments = lines[b].Split(',');
int count = lines.Length;
errors.Text = fragments[0] + count.ToString();
errors.Visible = true;
string first = fragments[0]; string last = fragments[1]; string email = fragments[2];
string phone = fragments[3]; string birth = fragments[4];
string addrecord = manager.AddContact(first, last, email, phone, birth, Request.QueryString["userid"]);
if (addrecord == "done")
{
error.Text = "Contact added check in the table below!";
error.Visible = true;
FillContacts(Request.QueryString["userid"]);
}
else
{
error.Text = addrecord;
error.Visible = true;
}
}
}
else
{
errors.Text = "No file with content was selected";
errors.Visible = true;
}
and this works quiet well....super!
|
|
|
|
|
You use indexof and substring function to retrieve only "Kiss".
foreach (string s in lines)
{
int i = s.indexof(',');
string sub = s.substring(0,i);
}
|
|
|
|
|
Because that is far more succinct than he currently has. Also, when he needs to process other elements your code should much easier to do than in than his own. Oh, hang on everything, except this sentence) is a whopping lie.
Dalek Dave: There are many words that some find offensive, Homosexuality, Alcoholism, Religion, Visual Basic, Manchester United, Butter.
Pete o'Hanlon: If it wasn't insulting tools, I'd say you were dumber than a bag of spanners.
|
|
|
|
|
i just give him answer. I think i forgot to remove foreach loop....
|
|
|
|
|
Actually, it looks more like the thing you needed to change you didn't and vice versa.
Dalek Dave: There are many words that some find offensive, Homosexuality, Alcoholism, Religion, Visual Basic, Manchester United, Butter.
Pete o'Hanlon: If it wasn't insulting tools, I'd say you were dumber than a bag of spanners.
|
|
|
|
|
hmmmmmm k i ll. Any way wat succit..
|
|
|
|
|
Uni-Vote all you like, my rep'll take it
Dalek Dave: There are many words that some find offensive, Homosexuality, Alcoholism, Religion, Visual Basic, Manchester United, Butter.
Pete o'Hanlon: If it wasn't insulting tools, I'd say you were dumber than a bag of spanners.
|
|
|
|
|
Nope. I've run that through every possible combination of Google Translate and it keeps coming back with the same response: You're a dribbling idiot.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Bad news for you mate. Under the new reputation system, your points total goes down everytime you post something stupid. It's only the daily cap limit that's stopping your reputation being minus several hundred thousand.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Instead of using a foreach construct to loop over all the lines use only the first line (if I understood your question correctly):
string[] lines = File.ReadAllLines(strFilename);
string[] fragments = lines[0].Split(',');
errors.Text += fragments[0];
errors.Visible = true;
|
|
|
|
|
Yes man you did understand my question,
this works exactly the way I want it to.
Thanks alot man
|
|
|
|
|
I am using VisualStudio 2005 version. My current project is Voice Enabled system with mail client. Voice enabled system is ready it recognize my voice and perform the instruction but the main problem lies in mail client.
When ever i run the program i get this error
Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))
On this line the error is being displayed
((System.ComponentModel.ISupportInitialize)(this.VoiceCmd)).EndInit();
|
|
|
|
|
did u use ocx componant in your application. Try not adding COM references to the dlls but add a COM reference to the ocx file
if you still have problems try to register the ocx with regsvr32
|
|
|
|
|
Hi,
I am creating a Process in C# and want to print my "strName" value to command prompt.
This code is not printing any value , please let me know the right code.
I know this code is wrong,,but if we pass Arguents then?
string strName = "Alex";
Process pr = new Process();
pr.StartInfo.FileName = "cmd.exe";
pr.Start();
Thanks
modified on Friday, April 9, 2010 10:14 AM
|
|
|
|
|
Have you tried going into the project properties and building it as a Console Application? Then just do:
Console.WriteLine(strName);
|
|
|
|
|
I am trying to do with process.
|
|
|
|
|
Using this code , and where to add new line of code which prints value to commandprompt.
string strName = "Alex";
Process pr = new Process();
pr.StartInfo.FileName = "cmd.exe";
pr.Start();
|
|
|
|
|
Ok, if you want to actually send commands to the prompt, as opposed to just outputting text, you can do that via standard input...
pr.StartInfo.FileName = "cmd.exe";
pr.StartInfo.UseShellExecute = false;
pr.StartInfo.RedirectStandardInput = true;
pr.Start();
pr.StartInput.WriteLine(strName);
Of course, "Alex" isn't a command, so this is just going to give an error.
If you're trying to do something else, you're going to have to be a little more clear, because your question is rather vague.
|
|
|
|
|
|
please i need the complation of 4 queen only by my code for my doctor
we start
desgin from
node class
bfs class
to top expirt
please try to find by this method in simple code
by use my class and add to classes the miss code
form has two buttons
and grid 4x4
picture here
http://yfrog.com/0s91807548j[^]
class Node
{
public bool[,] state { set; get; }
public Node parent { set; get; }
public List<Node> childs { get; set; }
public int level { get; set; }
public int Hfunction()
{
int res=0;
return res;
}
public void generate_child()
{
for (int i = 0; i < 4; i++)
{
bool[,] newstate = (bool[,])this.state.Clone();
Node child = new Node();
childs.Add(child);
child.parent = this;
child.level = this.level + 1;
newstate[child.level, i] = true;
child.state = newstate;
}
}
public bool visited { get; set; }
public Node GetBestChild()
{
int Min = int.MaxValue;
int min_index = -1;
Node BestChild = null;
for (int i = 0; i < 4;i++ )
{
int CurrentValue = this.childs[i].Hfunction();
if (CurrentValue < Min && this.childs[i].visited == false)
{
BestChild = this.childs[min_index];
BestChild.visited = true;
Min = CurrentValue;
min_index = i;
}
}
return BestChild;
}
class BFS
{
public Node BfsProcess(Node root)
{
Node soultion = null;
if (root.Hfunction() == 4)
{
return root;
}
else {
root.generate_child();
Node bestchild =null;
while ((bestchild = root.GetBestChild()) != null)
{
soultion = BfsProcess(bestchild);
}
return soultion;
}
}
}<pre>
<div class="signature"><div class="modified">modified on Friday, April 9, 2010 10:39 AM</div></div>
|
|
|
|
|
What a $hit question, can't see many helpful response coming your way!
Oh, and yes, you got a 1 from me.
Go read the sticky posts at the TOP OF THE FORUM, to see how to ASK A QUESTION PROPERLY
|
|
|
|
|
amrreko wrote: please i need the complation of 4 queen only by my code for my doctor
Damn!
Watched code never compiles.
|
|
|
|
|
amrreko wrote: please i need the complation of 4 queen
How many queens? 8 is the usual number.
amrreko wrote: only by my code for my doctor
Is this a medical emergency? Use TCP
amrreko wrote: we start
desgin from
node class
bfs class
to top expirt
nice hiaku.
amrreko wrote: please try to find by this method in simple code
by use my class and add to classes the miss code
What code? You haven't included any. I don't normally respond so sarcastic a way, but you haven't specified the problem, the question is unintelligible, you haven't said what you have done and you obviously haven't tried to do this yourself. We aren't going to do your homework for you. I suggest you read the FAQs.
Dalek Dave: There are many words that some find offensive, Homosexuality, Alcoholism, Religion, Visual Basic, Manchester United, Butter.
Pete o'Hanlon: If it wasn't insulting tools, I'd say you were dumber than a bag of spanners.
|
|
|
|
|
Aww, go easy on him...
Keith Barrow wrote: amrreko wrote:
we start
desgin from
node class
bfs class
to top expirt
nice hiaku.
The proper pattern is 5-7-5. He just needs a couple more syllables... I'm sure we could make this work.
You have to be patient with these guys... If they don't speak English as a first language, it's difficult to make a proper haiku.
|
|
|
|