So here is a utility class I use a lot to serialize and deserialize objects into and out of xml files:
public static class StorageManager<t>
{
public static void Store(string filename, T obj, FileMode mode)
{
try
{
FileStream fileStream = new FileStream(filename, mode);
using (fileStream)
{
DataContractSerializer serializer = new DataContractSerializer(typeof(T));
serializer.WriteObject(fileStream, obj);
}
}
catch (Exception ex)
{
Debug.WriteLine(">>> STORAGE FATAL ERROR - " + ex.Message + " <<<");
}
}
public static T Retrieve(string filename)
{
try
{
T obj = default(T);
if (File.Exists(filename))
{
using (FileStream fileStream = new FileStream(filename, FileMode.Open))
{
DataContractSerializer serializer = new DataContractSerializer(typeof(T));
obj = (T)serializer.ReadObject(fileStream);
}
}
return obj;
}
catch (Exception ex)
{
Debug.WriteLine(">>> ISO STORAGE FATAL ERROR - " + ex.Message + " <<<");
return default(T);
}
}
}</t>
To use this class, you need to create a class that holds the object you want to serialize. Something like this:
[Serializable]
public class DataPoint
{
public DateTime SampleTime;
public string SampleName;
public string SampleDataType;
public string SampleValue;
}
Calling the storage manager to save a collection of DataPoints is pretty easy:
StorageManager<Collection<DataPoint>>.Store(@"C:\temp\data.xml", _collectionOfDataPoints, FileMode.Append);
Retrieving the data is almost as easy:
Collection<datapoint> collectionOfDataPoints = StorageManager<collection><datapoint>>.Retrieve(@"C:\temp\data.xml");</datapoint></collection></datapoint>
There are some limits to this approach... for example, the objects must be serializable. There are some which are not (like Dictionary and Type) and you have to either change how you are storing them or otherwise work around it. You can get a lot more in depth with the DataContractSerializer if you really want to but I find it works great on its own if you keep the class you are serializing simple.
Once you have the objects in a collection, you can use a LINQ query to find what you want. There are tons of examples out there on Google for that so I wont go into it.
I would suggest that you create your airport code class in a class library. Then link it into your main project. You can also, then, link it into a management project where you would be able to enter the data (or otherwise import it) then use the storagehelper to serialize it out to an xml file that you can import into your app with the storage manager class. This way you have a behind-the-scenes app which will allow you to manage the airport codes XML file while your main program will simply consume that data into an in-memory collection which can be queried with LINQ.
As for updating the file using a web site, it can be as simple as uploading the file to a web site then having your app hit that URL and download the file. Again, there are lots of examples on how to form a web request and download a file into your app using a webclient or a stream.
Just remember that if this is running on Vista or higher, you can't save the file into the app directory. You will have to save it into the AppData folder which you can easily get from the Environment namespace.
Good luck!