Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
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]));
                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 26-Nov-12 8:05am
Edited 26-Nov-12 8:40am
v2
Comments
Richard MacCutchan at 26-Nov-12 14:09pm
   
What is the content of the file, are you sure that it is text?
farham_heidari at 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 at 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 at 26-Nov-12 14:39pm
   
it's my file
www.winmaildat.com/getfile.php?getfile=%2Ftnefhandlerp2UMOx%2Fwinmail.dat
Richard MacCutchan at 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 at 26-Nov-12 15:22pm
   
it's ok i find my problem
tnk alot
richcb at 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.

1 solution

Rate this: bad
good
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)
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 339
1 Sergey Alexandrovich Kryukov 119
2 DineshMaind 113
3 majid torfi 75
4 ChauhanAjay 73
0 Sergey Alexandrovich Kryukov 9,192
1 OriginalGriff 8,405
2 CPallini 2,613
3 Richard MacCutchan 2,231
4 Abhinav S 1,938


Advertise | Privacy | Mobile
Web04 | 2.8.140827.1 | Last Updated 26 Nov 2012
Copyright © CodeProject, 1999-2014
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