Click here to Skip to main content
12,956,278 members (68,630 online)
Rate this:
Please Sign up or sign in to vote.
See more:
can u see any wrong here ?
i use unicode
and firstget file with dat File extension and change to txt

if (textBox1.Text != "" && textBox2.Text!="" && textBox3.Text!="" && textBox15.Text!=""&& txtdate1.Text!="")
                string Rline;
                string temp;
                string[] dtemp;
                DateTime InDate = DateTime.Now;
                // reading file 
                string dir = Directory.GetCurrentDirectory();
                string MyPath = System.IO.Path.Combine(dir, textBox3.Text.ToLower());
                StreamWriter filewrite = new StreamWriter(@MyPath + ".txt",true, Encoding.Unicode);
                // Read the file and display it line by line.
                if (!File.Exists(@op.FileName.ToString().Replace("dat", "txt"))) 
                    File.Copy(@op.FileName.ToString(), @op.FileName.ToString().Replace("dat", "txt"));
                StreamReader Readfile = new StreamReader(@op.FileName.ToString().Replace("dat", "txt"));
                dtemp = txtdate1.Text.Split('/');
                InDate = shamsi2Miladi.shamsi2miladi(Convert.ToInt32(dtemp[0]),Convert.ToInt32(dtemp[1]),Convert.ToInt32(dtemp[2]));
                // Erorr Here Help Help
                while ((Rline = Readfile.ReadLine()) != null)
                        temp = Rline;
                        temp = temp.Substring(1, 5).Replace(" ", string.Empty);
                        MessageBox.Show(temp.Substring(6, 10));
                        if (Convert.ToInt32(temp) == Convert.ToInt32(textBox3.Text) && Convert.ToDateTime(temp.Substring(6, 10)) >= InDate)
                progressBar1.Value = 20;
                progressBar1.Value = 100;
                MessageBox.Show("گزارش به اتمام رسید ");
                textBox2.Text = "";
                textBox3.Text = "";
                MessageBox.Show("لطفا فیلد های داده شده  تکمیل نمایید ");

plz check this picture[^]

it's my file[^]
Posted 26-Nov-12 8:05am
Updated 26-Nov-12 8:40am
Richard MacCutchan 26-Nov-12 14:09pm
What is the content of the file, are you sure that it is text?
richcb 26-Nov-12 14:11pm
You are using the .txt file extension in your initial streamwriter. If your file has a file extension of .dat then it will not execute properly.
farham_heidari 26-Nov-12 14:16pm
yes i get it from a device that record enter and exit of people that device out put .dat and i can see file content with notepad i am sure it's txt
Richard MacCutchan 26-Nov-12 14:20pm
The error suggests that there are some non-text characters in the file which have crashed the StreamReader. I suggest you look at the file with a hex editor to see exactly what the contents are.
farham_heidari 26-Nov-12 14:39pm
it's my file
Richard MacCutchan 26-Nov-12 14:56pm
It works OK for me, I just read the file all the way through. It must be something else in your code that is going wrong. Try using your debugger to find exactly where the error is.
farham_heidari 26-Nov-12 15:22pm
it's ok i find my problem
tnk alot

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

if (Convert.ToInt32(temp) == Convert.ToInt32(textBox3.Text) && Convert.ToDateTime(temp.Substring(6, 10)) >= InDate

it was problem i changed temp and then want to pick substring i change it to

if (Convert.ToInt32(temp) == Convert.ToInt32(textBox3.Text) && Convert.ToDateTime(Rline.Substring(6, 10)) >= InDate)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 6,869
CHill60 3,550
Maciej Los 3,302
ppolymorphe 2,080
Jochen Arndt 1,973

Advertise | Privacy | Mobile
Web01 | 2.8.170525.1 | Last Updated 26 Nov 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100