0

Read a txt file line by line and files from folders, and random line from file, but all results turned out to be the same. What is the cause of this problem? I want to ramdom a template (.html) file from a folder, and random a line from a file but the value came out the same.

if (comboBox1.SelectedItem.ToString() == "Amazon")
       {
           affpathname = affcase1;
       }
       else if (comboBox1.SelectedItem.ToString() == "Clickbank")
       {
           affpathname = affcase2;
       }

           int postpermm = Convert.ToInt32(postperm.Text);

           this.timer1.Start();
           string pfile = textBox1.Text;
           DateTime startdatef = dateTimePicker1.Value;
           string startdateshorta = string.Format(System.Globalization.CultureInfo.CreateSpecificCulture("en-US"), "{0:yyyy-MM-dd-HH-mm-ss}", DateTime.Now);
           FileStream FileOut = new FileStream(Application.StartupPath + @"\" + "wordpress" + @"\" + startdateshorta + ".xml", FileMode.Create);
           StreamWriter sw = new StreamWriter(FileOut);


           StreamReader a = new StreamReader(pfile);

           string dd = null;
           while ((dd = a.ReadLine()) != null)
           {
               {
                   var rand = new Random();
                   IEnumerable<string> lines = File.ReadLines(@Application.StartupPath + @"\config\" + affpathname + @"\title_template.txt");
                   var lineToRead = rand.Next(1, lines.Count());
                   var line = lines.Skip(lineToRead - 1).First();
                   sw.Write(line);
                   sw.Write("\r\n");
               }
               {
                   var rr = new Random();
                   var files = Directory.GetFiles(@Application.StartupPath + @"\config\" + affpathname + @"\layout\", "*.*").Where(s => Regex.Match(s, @"\.(html|htm)$").Success);
                   string randFile = files.ToList()[rr.Next(0, files.Count())];
                   sw.Write(randFile);
                   sw.Write("\r\n");
                   sw.Write("\r\n");
               }

               if (comboBox1.SelectedItem.ToString() == "Amazon")
               {
                   affpathname = affcase1;
               }                   
               else if (comboBox1.SelectedItem.ToString() == "Other Aff")
               {
                   affpathname = affcase9;
               }

               string startdatelong = string.Format(System.Globalization.CultureInfo.CreateSpecificCulture("en-US"), "{0:ddd, dd MMM yyyy HH:mm:ss}", startdatef);
               string todaydatelong = string.Format(System.Globalization.CultureInfo.CreateSpecificCulture("en-US"), "{0:ddd, dd MMM yyyy HH:mm:ss}", DateTime.Now);

               string[] arr1 = dd.Split('@');
               {
                   string productname = arr1[0];
                   string productimg = arr1[1];
                   string productlink = null;
                   if (mutiaff.Checked)
                   {
                       productlink = arr1[2];
                   }
                   else
                   {
                       productlink = singleafflink.Text;
                   }
               }
           }

           sw.Write("</channel>\r\n");
           sw.Write("</rss>\r\n");
           sw.Close();
           FileOut.Close();
   }
bengoesboom
  • 2,119
  • 2
  • 23
  • 27
  • ex result http://www.thaicreate.com/dotnet/forum/100499.html – user2781826 Sep 15 '13 at 18:45
  • Title Template 9 C:\Users\User\documents\visual studio 2012\Projects\WindowsFormsApplication5\WindowsFormsApplication5\bin\Debug\config\1_amazon\layout\8 - Copy (4).html Title Template 9 C:\Users\User\documents\visual studio 2012\Projects\WindowsFormsApplication5\WindowsFormsApplication5\bin\Debug\config\1_amazon\layout\8 - Copy (4).html – user2781826 Sep 15 '13 at 18:47
  • What you need is not very much clear from your question ? Maybe the question need a brief explanation. – devavx Sep 15 '13 at 19:01
  • @aviral-singh random read file from folder and random read line from file but all results turned out to be the same. What is the cause of this problem? – user2781826 Sep 15 '13 at 19:06
  • 1
    http://stackoverflow.com/q/767999/4068 -- you're using Random incorrectly. – Austin Salonen Sep 15 '13 at 19:09
  • @aviral-singh simple result http://image.free.in.th/v/2013/ig/130916021356.JPG – user2781826 Sep 15 '13 at 19:10

0 Answers0