WinRT GetXmlDocument Utility


inline concurrency::task<Windows::Data::Xml::Dom::XmlDocument^> GetXmlDocument(Platform::String^ filename)
{
  using namespace Windows::Storage;

  auto folder = Windows::ApplicationModel::Package::Current->InstalledLocation;

  return create_task(folder->GetFileAsync(filename)).then([](StorageFile^ file)
  {
    auto doc = ref new Windows::Data::Xml::Dom::XmlDocument();
    return doc->LoadFromFileAsync(file);
  });
}

Posted in Uncategorized | Leave a comment

C++/CX Async reading from txt files that are in the .xap/installed folder

Little utility to read txt from a flat file with c++/cx windows 8 and windows phone 8 apps.

inline Platform::String^ LoadTxtFile(Platform::String^ filename)
{
  using namespace Windows::Storage;
  auto folder = Windows::ApplicationModel::Package::Current->InstalledLocation;

  Platform::Array<byte>^ data = nullptr;
  std::wstring dir = folder->Path->ToString()->Data(); 
  auto fullpath = dir.append(L"/").append(filename->Data());

  std::ifstream file(fullpath, std::ios::in | std::ios::ate);
  // if opened read it in
  if(file.is_open())
  {
    int length = (int) file.tellg();
    data = ref new Array<byte>(length);
    file.seekg(0, std::ios::beg);
    file.read(reinterpret_cast<char*>(data->Data), length);
    file.close();
  }

  std::wstring output;
  for(int i=0; i < data->Length; i++)
    output += data[i];
  
  return ref new Platform::String(output.c_str());
}
Posted in Uncategorized | Leave a comment

Ya I am blogging now ..

1272938115936

Posted in Uncategorized | Leave a comment