Click here to Skip to main content
15,893,722 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hello guys,

I would like to get data from a text file in asp.Net project.

Such as:

SKU# Product Description Manu. Code Quantity Unit Price
1 . 10071420 Kesir - Travertine Tiles 18CB 83 boxes (933.75 sq ft) $1.970 /sq ft
Denizli Beige / 18"x18"x1/2"



Is there anyone who knows how to do that?

Regards

Haluk
Posted
Updated 11-Aug-12 2:15am
v2
Comments
Volynsky Alex 11-Aug-12 8:19am    
Please see following example with VB.NET:
http://aspalliance.com/153_How_to_Read_a_text_file_in_ASP_NET_

What do you think about it:
C#
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace ReadTextFile
{
  class ReadText
  {
    static void Main(string[] args)
    {
      //- Location of the Text file
      string fileName = @"c:temptxt_test.TXT";
      //- Set the line counter
      int lineNumber = 0;

      //- Write initial text to the console
      Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
      Console.WriteLine("MY FAVORITE SONGS");
      Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");

      //- Open the text file
      using (StreamReader sr = new StreamReader(fileName))
      {
         //- Initialize name variables
         string aName = "";
         string sName = "";
         string alName = "";
         string line;    //- Holds the entire line

         //- Cycle thru the text file 1 line at a time pulling
         //- substrings into the variables initialized above
         while ((line = sr.ReadLine()) != null)
         {
            lineNumber++;

            //- Pulling substrings.  If there is a problem
            //- with the start index and/or the length values
            //- an exception is thrown
            try
            {
               aName = line.Substring(0,21).Trim();
               sName = line.Substring(22,25).Trim();
               alName = line.Substring(47,17).Trim();
            }

            catch (Exception ex)
            {
               Console.Write(ex.ToString());
            }

            //- Write the information to the console
            Console.WriteLine("Artist: {0}", aName);
            Console.WriteLine("Title : {0}", sName);
            Console.WriteLine("Album : {0}", alName);
            Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
         }
         sr.Close();
      }
    }
  }
}
 
Share this answer
 
Comments
haluk_78 11-Aug-12 9:35am    
Thank you Volynsky but I didnt get the result what I want exactly.
For example:

SKU - 10071420
Product Description - Kesir - Travertine Tiles Denizli Beige / 18"x18"x1/2"
Manu. Code - 18CB
Quantity - 83 boxes (933.75 sq ft)
Unit Price - $1.970 /sq ft

I want to get all above datas to the asptextboxes and asplabels...

I hope you understand what I mean
[no name] 11-Aug-12 11:01am    
So? Do it. There is nothing stopping you. You are the only one that knows what textboxes, labels and other controls you have. We cannot be mind readers.
 
Share this answer
 
Comments
haluk_78 11-Aug-12 9:37am    
The example is very nice... but I dont know whether it's for me... As I said just now that:

SKU - 10071420
Product Description - Kesir - Travertine Tiles Denizli Beige / 18"x18"x1/2"
Manu. Code - 18CB
Quantity - 83 boxes (933.75 sq ft)
Unit Price - $1.970 /sq ft

I want to get all above datas to the asptextboxes and asplabels...

I hope you understand what I mean
Just reading data from a text file? It would be very easy with just 3 lines of code..
// create reader & open file
TextReader tr = new StreamReader(@"C:\" + "yourData.txt");

// read a line of text
richTextBox1.Text = tr.ReadToEnd(); //show data here in your asp page

// close the stream
tr.Close();

And of course not to forget to include System.IO namespace..
 
Share this answer
 
C#
protected void bt_Upload_Click(object sender, EventArgs e)
        {
            //dosya içeriği
            byte[] temp = ds_Gonder.FileBytes;
            //dosya adı
            string[] dosya = ds_Gonder.FileName.Split('.');
            dosya[0] = ks.SUrun_Satis.DsKyIndeks().ToString();
            string name = dosya[0].ToString() + "." + dosya[1].ToString();
            //sunucu adresi
            string path="";
            string dosya_ac = "";
            if (cm_Belge_Kriter.SelectedIndex != 0)
            {
                path = "ftp://url/";
                dosya_ac = @"~/Satislar/";
            }
            else
            {
                path = "ftp://url2/";
                dosya_ac = @"~/SatisIslemi/";
            }
            WebClient wc = new WebClient();
            //ftp -> kullanıcı adı ve parola
            wc.Credentials = new NetworkCredential("www.website.com", "HYBwx2fAOJ3X");
            wc.UploadData(
            string.Concat(path, name)
            , temp);
            lbl_dosya.Text = "1";          
 
            //SATIŞ İŞLEMİ YAPABİLMEK İÇİN
            if (cm_Belge_Kriter.SelectedIndex == 0)
            {
                StreamReader rd = new StreamReader(Server.MapPath(dosya_ac + name));
 
                ArrayList liste = new ArrayList();
                string[] _liste = rd.ReadToEnd().ToString().Split(' ');
                for (int i = 0; i < _liste.Length; i++)
                {
                    string deger = _liste[i].ToString();
                    if (deger != "")
                    {
                        liste.Add(deger);
                    }
                }
                string depo = "";
                string urun_kod = "";
                ArrayList listmusteri = ks.SUrun_Satis.TxMusteriAdDondur();
                ArrayList listbdno = ks.SUrun_Satis.TxBdNoDondur();
                int _dpindeks = 0;
                for (int i = 0; i < liste.Count; )
                {
                    string veri = liste[i].ToString();
                    for (int k = 0; k < listmusteri.Count; )
                    {
                        string _ms = listmusteri[k].ToString();
                        string _musteri = _ms.Remove(_ms.IndexOf(',') + 1);
                        if (veri.Contains(_musteri))
                        {
                            depo = _musteri;
                            _dpindeks = k;
                        }
                        k++;
                    }
                    for (int j = 0; j < listbdno.Count; )
                    {
                        string _bdno = listbdno[j].ToString();
                        if (veri.Contains(_bdno))
                        {
                            urun_kod = ks.SUrun_Satis.UrunKodDondur(_bdno) + "/" + _bdno;
                        }
                        j++;
                    }
                    i++;
                }
 
                tx_Po.Text = liste[liste.IndexOf("No.:") + 1].ToString().Substring(4, 6);
                string tarih = liste[liste.IndexOf("Date:") + 1].ToString() + "," + liste[liste.IndexOf("Date:") + 2].ToString() + liste[liste.IndexOf("Date:") + 3].ToString().Remove(4);
                tx_kutuAdet.Text = liste[liste.IndexOf("boxes") - 1].ToString();
                string _tutar = liste[liste.IndexOf("boxes") + 4].ToString().Remove(0, 3);
                //tutarla ilgili kontrollar
                string tutar = "";
                if (_tutar.Contains(','))
                {
                    tutar = _tutar.Remove(_tutar.IndexOf(','), 1);
                }
                else
                {
                    tutar = _tutar;
                }
                txt_BirimFiyat.Text = tutar.Replace('.', ',');
                dtGirisTarihi.Value = Convert.ToDateTime(tarih);
                //deponun yüklenmesi
                string silinecek = urun_kod;
                string _silinecek = listmusteri[_dpindeks].ToString();
                drpUrunKodu.Text = urun_kod;
                if (drpUrunKodu.Text != "--Choose An Item--" && drpDepo.Text == "")
                {
                    string[] lsurun_kod = drpUrunKodu.Text.Split('/');
                    string _urun = lsurun_kod[0].ToString();
                    drpDepo.Items.Clear();
                    drpDepo.Items.Add(new ListItem("--Choose An Item--"));
                    foreach (var item in ks.SUrun_Satis.DepoListesiDondur(_urun))
                    {
                        drpDepo.Items.Add(new ListItem(item.ToString()));
                    }
                }
 
                drpDepo.Text = _silinecek;
                if (drpDepo.Text != "--Choose An Item--")
                {
                    txtKasaID.Items.Clear();
                    string _depo = drpDepo.Text;
                    foreach (var item in ks.SUrun_Satis.KasaIdListDondur(_depo))
                    {
                        txtKasaID.Items.Add(new ListItem(item.ToString()));
                    }
                    string[] lsurun_kod = drpUrunKodu.Text.Split('/');
                    string _urun = lsurun_kod[0].ToString();
                    int kasa = Convert.ToInt32(txtKasaID.Text);
                    ks.SUrun_Satis.UrunDegerDondur(drpDepo.Text, _urun, kasa);
                    lb_Kasa_Satis.Text = ks.SUrun_Satis.KasaSatis.ToString();
                    lb_Kasa_Stok.Text = ks.SUrun_Satis.KasaStok.ToString();
                    lb_Urun_Satis.Text = ks.SUrun_Satis.KutuSatis.ToString();
                    lb_Urun_Stok.Text = ks.SUrun_Satis.KutuStok.ToString();
                    lb_Urun_Su.Text = ks.SUrun_Satis.KutuSu.ToString();
 
                }
                rd.Close();
 

                //ürünle ilgili işlemler
                int kutu_adet = Convert.ToInt32(tx_kutuAdet.Text);
                ks.SUrun_Satis.TxSatisIdListDoldur(kutu_adet, drpDepo.Text);
                for (int i = 0; i < ks.SUrun_Satis.List_UrunId.Count; i++)
                {
                    string urunid = ks.SUrun_Satis.List_UrunId[i].ToString();
                    string urunadet = ks.SUrun_Satis.List_UrunAdet[i].ToString();
                    ls_Kasa_Listesi.Items.Add(new DevExpress.Web.ASPxEditors.ListEditItem(urunid + " " + urunadet));
                }
 
                ls_Kasa_Listesi.Items.Add(new DevExpress.Web.ASPxEditors.ListEditItem(""));
                ls_Kasa_Listesi.Items.Add(new DevExpress.Web.ASPxEditors.ListEditItem("TOPLAM : "+kutu_adet.ToString()));
            }
        }
 
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