Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
C# equivalent of Appe from
Message
From
11/12/2007 08:27:25
John Baird
Coatesville, Pennsylvania, United States
 
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01274325
Message ID:
01274745
Views:
11
>Hi John.
>Thanks for your help.
>I think I will end up writin g code to import the CSV file..I think its probably the cleanest and least complicated.
>If you had any pointers on how to do this I'd appreciate it.
>


This is part of the import file service:
        /// <summary>
        /// Import delimited text file service.
        /// </summary>
        /// <param name="fileName">CSV File to Import </param>
        /// <returns>imported datatable</returns>
        public List<string> ImportDelimited(string fileName)
        {
            StreamReader sr = null;
            List<string> list = new List<string>();
            try
            {
                sr = new StreamReader(fileName);
                while (!sr.EndOfStream)
                {
                    list.Add(sr.ReadLine());
                }

            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                sr.Close();
            }
            return list;
        }
this is a sample import from a compact app I have:
        /// <summary>
        /// Load thing data to SQL
        /// </summary>
        /// <param name="fileName">CSV File to Import </param>
        public void LoadThingDataToSQL(string fileName)
        {
            _dtThing = new ThingDataSet.ThingsDataTable();
            ThingDataSet.ThingsRow dr = null;
  
            try
            {
                BDImportService bis = new BDImportService();
                List<string> list = bis.ImportDelimited(fileName);
                foreach (string s in list)
                {
                    string[] sa = s.Split(",".ToCharArray());

                    dr = _dtThing.NewThingsRow();
                    //were grabbing the taxonomy name here, we'll translate the foreign keys
                    //in another step.
                    dr.Taxonomy = sa[_dtThing.TaxonomyColumn.Ordinal - 1];
                    dr.Name = sa[_dtThing.NameColumn.Ordinal - 1];
                    dr.Seen = Convert.ToBoolean(sa[_dtThing.SeenColumn.Ordinal-1].Equals("0") ? false : true);
                    dr.CommonName = sa[_dtThing.CommonNameColumn.Ordinal-1];
                    dr.ScientificName = sa[_dtThing.ScientificNameColumn.Ordinal-1];
                    dr.SortOrder = (float)(Convert.ToDecimal(sa[_dtThing.SortOrderColumn.Ordinal - 1]));

                    _dtThing.AddThingsRow(dr);
                }
                
                this.UpdateThingTable(_dtThing);

            }
            catch (Exception e)
            {
                throw e;
            }
        }
Hope this helps....
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform