locked
Import (txt) file into Lightswitch RRS feed

  • Question

  • Hi,

    I need to import the data from a text file into my grid. Any help is appricated.

    SE_NR	ADR_SPED_VERSCH	SZ	VU_NR	PS_NR	VERPACKUNG	LAENGE	BREITE	HOEHE	VOLUMEN	BRUTTO	KUNDE
    900775	KARL HEINZ DIETRICH	4	466871	2	KARTON	1	0,14	0,14	0,02	1	SINGAPORE 639526
    901838	KARL HEINZ DIETRICH	28	468011	5	EUROPAL	1,2	0,8	1,15	1,104	477	BEIJING 100102, P.R. CHINA
    901838	KARL HEINZ DIETRICH	28	468011	3	EUROPAL	1,2	0,8	1,15	1,104	488	BEIJING 100102, P.R. CHINA
    901838	KARL HEINZ DIETRICH	28	468011	4	EUROPAL	1,2	0,8	1,15	1,104	477	BEIJING 100102, P.R. CHINA
    901838	KARL HEINZ DIETRICH	28	468011	1	EUROPAL	1,2	0,8	1,15	1,104	477	BEIJING 100102, P.R. CHINA
    901838	KARL HEINZ DIETRICH	28	468011	2	EUROPAL	1,2	0,8	1,15	1,104	477	BEIJING 100102, P.R. CHINA
    901838	KARL HEINZ DIETRICH	28	468011	6	KART.A.PAL	2,25	0,32	0,8	0,576	44	BEIJING 100102, P.R. CHINA
    901837	KARL HEINZ DIETRICH	70	467984	16	KART.A.PAL	2	1,15	0,95	2,185	76	BEIJING 100102, P.R. CHINA
    901837	KARL HEINZ DIETRICH	70	467984	19	KARTON	1,01	0,31	0,18	0,056	6,8	BEIJING 100102, P.R. CHINA
    901837	KARL HEINZ DIETRICH	70	467984	17	KARTON	1,01	0,31	0,18	0,056	3,6	BEIJING 100102, P.R. CHINA
    901837	KARL HEINZ DIETRICH	70	467984	18	KARTON	1,01	0,31	0,18	0,056	5,4	BEIJING 100102, P.R. CHINA
    901837	KARL HEINZ DIETRICH	70	467984	1	KART.A.PAL	1,13	0,79	0,85	0,759	66	BEIJING 100102, P.R. CHINA
    901837	KARL HEINZ DIETRICH	70	467984	3	KART.A.PAL	1,13	0,79	0,85	0,759	56,5	BEIJING 100102, P.R. CHINA
    901837	KARL HEINZ DIETRICH	70	467984	4	KART.A.PAL	1,13	0,8	1,24	1,121	122	BEIJING 100102, P.R. CHINA
    901837	KARL HEINZ DIETRICH	70	467984	10	KARTON	1,02	0,62	0,31	0,196	24,1	BEIJING 100102, P.R. CHINA
    901837	KARL HEINZ DIETRICH	70	467984	9	KART.A.PAL	1,13	0,79	0,85	0,759	69	BEIJING 100102, P.R. CHINA
    901837	KARL HEINZ DIETRICH	70	467984	6	KART.A.PAL	1,13	0,79	0,85	0,759	60	BEIJING 100102, P.R. CHINA
    901837	KARL HEINZ DIETRICH	70	467984	2	KART.A.PAL	1,13	0,79	0,85	0,759	144	BEIJING 100102, P.R. CHINA
    901837	KARL HEINZ DIETRICH	70	467984	12	KART.A.PAL	1,13	0,79	0,85	0,759	50	BEIJING 100102, P.R. CHINA
    901837	KARL HEINZ DIETRICH	70	467984	7	KART.A.PAL	1,13	0,8	1,24	1,121	67	BEIJING 100102, P.R. CHINA
    901837	KARL HEINZ DIETRICH	70	467984	15	KART.A.PAL	2	1,15	0,95	2,185	59	BEIJING 100102, P.R. CHINA
    901837	KARL HEINZ DIETRICH	70	467984	5	KART.A.PAL	1,13	0,79	0,85	0,759	65	BEIJING 100102, P.R. CHINA
    901837	KARL HEINZ DIETRICH	70	467984	11	KART.A.PAL	2	1,15	0,95	2,185	114	BEIJING 100102, P.R. CHINA
    901837	KARL HEINZ DIETRICH	70	467984	13	KART.A.PAL	2	1,15	0,95	2,185	185	BEIJING 100102, P.R. CHINA
    901837	KARL HEINZ DIETRICH	70	467984	14	KART.A.PAL	2	1,15	0,95	2,185	112	BEIJING 100102, P.R. CHINA
    901837	KARL HEINZ DIETRICH	70	467984	8	KART.A.PAL	1,13	0,79	0,85	0,759	88	BEIJING 100102, P.R. CHINA
    901838	KARL HEINZ DIETRICH	70	468015	13	KART.A.PAL	0,8	0,6	0,67	0,322	40,5	BEIJING 100102, P.R. CHINA
    901838	KARL HEINZ DIETRICH	70	468015	15	KARTON	0,52	0,41	0,38	0,081	19,7	BEIJING 100102, P.R. CHINA
    901838	KARL HEINZ DIETRICH	70	468015	14	KART.A.PAL	1,13	0,79	0,85	0,759	44	BEIJING 100102, P.R. CHINA
    901838	KARL HEINZ DIETRICH	70	468015	7	KART.A.PAL	1,13	0,79	0,85	0,759	61,5	BEIJING 100102, P.R. CHINA
    901838	KARL HEINZ DIETRICH	70	468015	8	KART.A.PAL	1,13	0,79	0,85	0,759	61,5	BEIJING 100102, P.R. CHINA
    901838	KARL HEINZ DIETRICH	70	468015	6	KART.A.PAL	1,13	0,79	0,85	0,759	61	BEIJING 100102, P.R. CHINA
    901838	KARL HEINZ DIETRICH	70	468015	9	KART.A.PAL	1,13	0,79	0,85	0,759	92	BEIJING 100102, P.R. CHINA
    901838	KARL HEINZ DIETRICH	70	468015	1	KART.A.PAL	1,13	0,79	0,85	0,759	58,5	BEIJING 100102, P.R. CHINA
    901838	KARL HEINZ DIETRICH	70	468015	4	KART.A.PAL	1,13	0,8	1,24	1,121	129,5	BEIJING 100102, P.R. CHINA
    901838	KARL HEINZ DIETRICH	70	468015	2	KART.A.PAL	1,13	0,79	0,85	0,759	96,5	BEIJING 100102, P.R. CHINA
    901838	KARL HEINZ DIETRICH	70	468015	3	KART.A.PAL	1,13	0,79	0,85	0,759	62,5	BEIJING 100102, P.R. CHINA
    901838	KARL HEINZ DIETRICH	70	468015	10	KART.A.PAL	1,13	0,79	0,85	0,759	78	BEIJING 100102, P.R. CHINA
    901838	KARL HEINZ DIETRICH	70	468015	11	KART.A.PAL	1,13	0,79	0,85	0,759	97,5	BEIJING 100102, P.R. CHINA
    901838	KARL HEINZ DIETRICH	70	468015	12	KART.A.PAL	1,13	0,79	0,85	0,759	61,5	BEIJING 100102, P.R. CHINA
    901838	KARL HEINZ DIETRICH	70	468015	5	KART.A.PAL	1,13	0,79	0,85	0,759	135	BEIJING 100102, P.R. CHINA

    Monday, May 28, 2012 3:44 PM

Answers

  • You would have to write different code to import form XLS, XML or CSV. The article pointed to above, http://ourbizforward.com/LightSwitchTips?ID=79 , deals with CSV files only.

    CSV files are just a special case of a text file where each value is separated from the next by a comma and a new line represents a new record. String values may be enclosed in quotes. Values with currency symbols or numbers formatted for different locales can cause problems (EG using a comma for the decimal separator) which you may have to code around.

    The data you showed above may be fixed length fields, not CSV, or it may be Tab delimited. Both are simple variants of Text files and relatively simple to deal with as shown in the article at LightSwitchTips.


    Simon Jones
    If you found this post helpful, please "Vote as Helpful". If it actually answered your question, please remember to "Mark as Answer". This will help other people find answers to their problems more quickly.

    • Marked as answer by Otomii Lu Thursday, June 7, 2012 1:56 AM
    • Unmarked as answer by Otomii Lu Thursday, June 7, 2012 2:10 AM
    • Proposed as answer by Otomii Lu Thursday, June 7, 2012 2:10 AM
    • Marked as answer by Otomii Lu Thursday, June 14, 2012 1:35 AM
    Wednesday, June 6, 2012 9:54 AM

All replies

  • Hello Jürgen,

    Create a new SQL Server database and import the flat file to the database. In LightSwitch connect to this database as "External datasource".

    Other option is to create a RIA service, which manage the data access to the flat file directly.


    Olaf Helper
    * cogito ergo sum * errare humanum est * quote erat demonstrandum *
    Wenn ich denke, ist das ein Fehler und das beweise ich täglich
    Blog Xing


    Monday, May 28, 2012 4:36 PM
  • If the data is comma delimited, tab delimited, or fixed length fields, you could import the data into Excel and then use the LightSwitch Excel Importer tool.

    If you need a "one-click" solution for the users then you can create your own import mechanism, opening the file for reading, reading a line at a time and splitting the line at the Tab characters or at specific lengths.


    Simon Jones
    If you found this post helpful, please "Vote as Helpful". If it actually answered your question, please remember to "Mark as Answer". This will help other people find answers to their problems more quickly.

    Monday, May 28, 2012 5:25 PM
  • Thanks Olaf and Simon

    I'll try it, this is the first step to a simple stock inventory counting. I would check with a barcode scanner.

    i can't create a  RIA service with Lightswitch, i think i need Visual Studio Pro for that  or not?




    Monday, May 28, 2012 6:30 PM
  • Hello Jürgen,

    You can use also the free Express Edition of VS (C#/VB/Web) to create a RIA service.


    Olaf Helper
    * cogito ergo sum * errare humanum est * quote erat demonstrandum *
    Wenn ich denke, ist das ein Fehler und das beweise ich täglich
    Blog Xing

    Monday, May 28, 2012 6:51 PM
  • Thanks Olaf,

    that would be very good with the RIA service because I should update the list every day :)

    Monday, May 28, 2012 7:02 PM
  • Monday, May 28, 2012 7:13 PM
  • No, just the one you prefer.

    Web is dedicated for web (service) development, where you can start project s eighter in C# or VB.NET.


    Olaf Helper
    * cogito ergo sum * errare humanum est * quote erat demonstrandum *
    Wenn ich denke, ist das ein Fehler und das beweise ich täglich
    Blog Xing

    Monday, May 28, 2012 7:56 PM
  • If you install the ExcelImporter extension, you can paste that data into an excel file and easily import it.

    The excel file has to have column headers in the first row, data below, no blank spaces. 

    The command for importing in excel is: 

    ExcelImporter.Importer.ImportFromExcel(Me.*YourEntityNameHere*)

    • Proposed as answer by sj-- Thursday, May 31, 2012 2:40 PM
    Thursday, May 31, 2012 2:40 PM
  • Hi,

    I import data from csv every day too, I wrote my own costum import function in lightswitch.

    So I user is able to import or refresh the data.

    I wrote a costum import function to filter the data which is already in the table etc.

    But it also depends on how many rows or data you want to import.

    If you are interested to write your costum import function, I am going to post some code snipets to help you.

    Thursday, May 31, 2012 2:48 PM
  • Hi

    Here is an article from William Stacey. May be this one help you to solve your issue.

    http://ourbizforward.com/LightSwitchTips?ID=79

    Regards


    Rashmi Ranjan Panigrahi

    Thursday, May 31, 2012 2:59 PM
  • Hi
     I had a lot of work last week but thanks for your help.
    How can I see if from xls, csv or txt it always the same way.
    And what about XML?

    Thanks Dragonalw, I would like some codes.
    Sunday, June 3, 2012 4:41 PM
  • You would have to write different code to import form XLS, XML or CSV. The article pointed to above, http://ourbizforward.com/LightSwitchTips?ID=79 , deals with CSV files only.

    CSV files are just a special case of a text file where each value is separated from the next by a comma and a new line represents a new record. String values may be enclosed in quotes. Values with currency symbols or numbers formatted for different locales can cause problems (EG using a comma for the decimal separator) which you may have to code around.

    The data you showed above may be fixed length fields, not CSV, or it may be Tab delimited. Both are simple variants of Text files and relatively simple to deal with as shown in the article at LightSwitchTips.


    Simon Jones
    If you found this post helpful, please "Vote as Helpful". If it actually answered your question, please remember to "Mark as Answer". This will help other people find answers to their problems more quickly.

    • Marked as answer by Otomii Lu Thursday, June 7, 2012 1:56 AM
    • Unmarked as answer by Otomii Lu Thursday, June 7, 2012 2:10 AM
    • Proposed as answer by Otomii Lu Thursday, June 7, 2012 2:10 AM
    • Marked as answer by Otomii Lu Thursday, June 14, 2012 1:35 AM
    Wednesday, June 6, 2012 9:54 AM