Click here to Skip to main content
15,892,161 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
can u see any wrong here ?
i use unicode
and firstget file with dat File extension and change to txt

C#
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]));
                MessageBox.Show(InDate.ToString());
                // 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)
                        {
                            filewrite.WriteLine(Rline);
                        }
                    }
                progressBar1.Value = 20;
                Readfile.Close();
                filewrite.Close();
                progressBar1.Value = 100;
                MessageBox.Show("گزارش به اتمام رسید ");

                textBox2.Text = "";
                textBox3.Text = "";
                
            }
            else
            {
                MessageBox.Show("لطفا فیلد های داده شده  تکمیل نمایید ");
            }

plz check this picture
http://uploadfa.net/uploads/13539564541.png[^]

it's my file
www.winmaildat.com/getfile.php?getfile=%2Ftnefhandlerp2UMOx%2Fwinmail.dat[^]
Posted
Updated 26-Nov-12 8:40am
v2
Comments
Richard MacCutchan 26-Nov-12 14:09pm    
What is the content of the file, are you sure that it is text?
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
www.winmaildat.com/getfile.php?getfile=%2Ftnefhandlerp2UMOx%2Fwinmail.dat
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.

1 solution

C#
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

C#
if (Convert.ToInt32(temp) == Convert.ToInt32(textBox3.Text) && Convert.ToDateTime(Rline.Substring(6, 10)) >= InDate)
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900