Query a text file

Hello everyone, thank you for reading my post. I am very new user working with Xamarin Forms on a cross-platform app in C#. I have a text file that I have saved into a google drive (not married to this part any cloud connection is fine) that syncs automatically to a folder on my phone. I would like to query the data in that text file. I know I can use SQLite in Xamarin, but I am not sure if I can link a table to text file using commas as a separator. If there is a better way I am happy to try what you may suggest. I am familiar with Linq, and can use arrays. If it is better the store the text file in another format like XML or JSON I can do that too. I am just looking for a nudge in the right direction and you help is appreciated. I have not included code because I am very early in my process. I just don't want to travel to far down the wrong path when I start, thank again.

Best Answers

Answers

  • This is useful thank you. My real issue is the part you assumed I know ;)... I have the file in my android device in location
    Device storage>Documents>PWI>Lot Quantities2.txt
    And it will dynamically update through the cloud link.
    I could get to the file in windows with something like
    System.IO.StreamReader file = new System.IO.StreamReader(@C:\sample.txt)
    But I am not sure how to do this on my device.
    I may be making it to difficult I realize...Do you know how to reference it?
    Thank you!!!

  • adamkempadamkemp USInsider, Developer Group Leader mod

    As you found when doing this on Android and Windows already the location of the file (and even the format of the path) might vary between platforms, and there are many possible places that file could be. So I can't really answer your question without more information. First, on which device will you be running this code? And second, how will the file get onto the device? Does it ship with the app? Do you want to download it from a URL? There are many different ways of doing this so you need to be really specific to get a useful answer.

  • Excellent, thank you. I believe you are understanding my question. I am using a Samsung S4, but I would like this application to be able to work on multiple devices without uniquely customized set up. The file path I gave you is auto synced through google drive. The actual text file is in my google drive folder as well. If reading it from there would make my program more universally friendly I would prefer to read it from google drive (or any open cloud source if something else is better). I mentioned earlier that I can change the format of the file from .txt to whatever makes this easiest, and you were spot on in the CSV comment. The queries I will be running are not difficult for me. My issue is really just reading the data into an array an any device. Thanks again for all your help!

  • The content of the text file automatically updates from a server at my job. The views by users should all be the same, and the app will be read only. I will not require any data to be loaded back to the file from the app. What is being viewed is my warehouse inventory. The text file is just list of the items in the warehouse and their location. The text file is automatically overwritten every 10 minutes. I have a copy being loaded by another application that updates the Google drive file and is then available on my phone (and perhaps to my app????).

    I think that answers all the questions you ask. Thanks again.

  • I think this will get me what I am looking for. I will start going through the information now. Thank you!

Sign In or Register to comment.