0

I need to read xml csv and other files like xml for editing elements and their values, need universal converter to object for read files show elements and tags for editing elements, and how read from converted object?

Please help how can I do that ?

It must be part of big asp.net mvc project and I'm new in mvc, and don't be strong with me this is my first normal question

Thanks

tereško
  • 58,060
  • 25
  • 98
  • 150
  • 1
    It is worth to have a look at LinqToXML. However I am not able to help you unless your answer is more specific – Alex Mar 26 '14 at 12:33
  • I need universal web app to read files in xml or csv format and edit this files in xml or csv formats – user3359460 Mar 26 '14 at 12:43

1 Answers1

0

Either way, I am not sure that there exists an already made solution specific to what you need. Many people have probably implemented something like this in their program before but it had to be written. CSV and XML file formats are both very common and there exists a lot of support for reading and writing of both. I highly recommend using LINQ as it has a lot of great features for dealing with iterating through things such as elements in an XML file or elements in a CSV file.

For this problem I would use a switch statement that reads in the file paths and then calls another method to read the specific file that you have. There is no (at least that I know of) NuGet package that handles all text files etc. and I did do a quick search before I posted this.

var extension = Path.GetExtension(fileName);
switch (extension)
{
    case ".xml":
        ConvertXmlFile(file);
        break;
    case ".csv":
        ConvertCsvFile(file);
        break;
}

Inside each of the two methods in the switch statement you will need to transform the file into the object that you need to continue on in your program. Here are two links that should help and a lot more in depth that what I can do here:
XML: http://www.codeproject.com/Tips/366993/Convert-XML-to-Object-using-LINQ
CSV: Read Csv using LINQ
Finding file extensions: http://msdn.microsoft.com/en-us/library/system.io.path.getextension(v=vs.110).aspx

Hope this helps.

Community
  • 1
  • 1
Jordan_Walters
  • 2,199
  • 1
  • 12
  • 9
  • can I using LINQ TO XML for convert both files (xml,csv) to object? i need universal converter for convert posted any files like xml,csv,doc and other?? – user3359460 Mar 26 '14 at 13:11
  • I would like to make sure I have your question right. You are using an MVC application that can receive various sorts of files: xml, csv, doc, etc and you would like to use a single method to convert those files into an object? I am assuming that all of those objects will contain the same data. For example, student enrollment information? – Jordan_Walters Mar 26 '14 at 14:15
  • if you can help how can I organized this method – user3359460 Mar 27 '14 at 05:20