Here is another alternative. Close the file and paste it into the clientBin folder next to the application XAP. Then at the application point where the content is required, do something like this: -
public void GetWordFrequencyResource(Action<string> callback) { WebClient client = new WebClient(); client.OpenReadAsync += (s, args) => { try { var zipRes = new StreamResourceInfo(args.Result, null) var txtRes = Application.GetResourceStream(zipRes, new Uri("WordFrequency.txt", UriKind.Relative)); string result = new StreamReader(txtRes.Stream).ReadToEnd(); callback(result); } catch { callback(null);
Usage: -
var wordFrequency = new Dictionary<string, int>(); GetWordFrequencyResource(s => {
The above code allows you to store the file in an efficient zip format, but not in XAP itself. Therefore, you can download it on demand. It uses the fact that XAP is a zip file, so Application.GetResourceStream , which is designed to extract resources from XAP files, can be used in a zip file.
By the way, I really do not suggest you use a dictionary, I just use the dictionary as a simple example. In fact, I would suggest that the file is in an ordered order. If so, you can use KeyValuePair<string, int> for each record, but create your own collection type that stores them in an array or List , and then use some binary search methods to index it.
source share