locked
How to display Files from a HealthVault Record in an application RRS feed

  • Question

  • Are there any samples available around how to display a file from a HealthVault record.

    I have the following code:
    {

        HealthRecordSearcher searcher = PersonInfo.SelectedRecord.CreateSearcher();

        HealthRecordFilter filter = new HealthRecordFilter(File.TypeId);

        searcher.Filters.Add(filter);

        HealthRecordItemCollection files = searcher.GetMatchingItems()(0);

        foreach (File f in files) {

            list.Items.Add(f.Name);

        }

    }

    This code retreives all the files from the record and displays in a drop down list. Now, I want to let the user select a file and view it.

    Is there a code sample available around this?

    Friday, July 10, 2009 5:55 PM

Answers

  • that is what I was missing.

    I was able to retrieve the content of the file by this code.

    byte[] filecontents = null;

        filecontents = Convert.FromBase64String(f.OtherData.Data.ToString);

        string filetext = null;

        filetext = Encoding.UTF8.GetString(filecontents);

    Thanks a lot for your quick response.

    Friday, July 10, 2009 6:48 PM
  • Got it-- the contents of the file are contained in the "OtherData" section, which is not included by default:

    The OtherData section doesn't come down by default, so if you want to get the contents of the file back, you specify:

    filter.View.Sections = HealthRecordItemSections.All;

    (or another version of the Sections mask that includes HealthRecordItems.OtherData).

    For more, check out the following How To Guide: http://msdn.microsoft.com/en-us/healthvault/cc308552.aspx

    Friday, July 10, 2009 6:19 PM

All replies

  • Once you have retrieved a File, it is up to your application to determine what to do with it and handle the user interaction.  I don't believe we have code samples for a UX around this.
    Friday, July 10, 2009 6:12 PM
  • Okay, posted slightly too quickly--

    There are lots of code samples for handling HealthVault data for both reading and writing; I don't know if there is one that specifically handles the "File" data type, but for most of the UX around HealthVault types check out the sample applications contained in the .NET SDK download.  The How-To guides can also be helpful, and Eric Gunnerson's blog has a great series with code samples.

    I don't know that we'll provide code samples for how to do the UX for every type-- the idea is that we provide samples for how to handle a number of representative types, but that applications are primarily responsible for application UX on top of the HealthVault platform, as  HealthVault is primarily a data platform.
    Friday, July 10, 2009 6:15 PM
  • I am only able to retrieve the name of the file or other properties. Is there any way to retrieve the actual file? Or is there any way we could programactially create a URL that points to the file in the HealthVault?

    Friday, July 10, 2009 6:15 PM
  • Ah-- that's a slightly different question.  You should definitely be able to retrieve the actual file.  You can't create a URL that points directly to the file in HealthVault, as that would be a security risk-- the file can only be accessed over a secure application connection, or by the user directly in the HealthVault administrative UI.

    Let me quick take a look at the how to fetch the file contents question, be right back-
    Friday, July 10, 2009 6:17 PM
  • Got it-- the contents of the file are contained in the "OtherData" section, which is not included by default:

    The OtherData section doesn't come down by default, so if you want to get the contents of the file back, you specify:

    filter.View.Sections = HealthRecordItemSections.All;

    (or another version of the Sections mask that includes HealthRecordItems.OtherData).

    For more, check out the following How To Guide: http://msdn.microsoft.com/en-us/healthvault/cc308552.aspx

    Friday, July 10, 2009 6:19 PM
  • that is what I was missing.

    I was able to retrieve the content of the file by this code.

    byte[] filecontents = null;

        filecontents = Convert.FromBase64String(f.OtherData.Data.ToString);

        string filetext = null;

        filetext = Encoding.UTF8.GetString(filecontents);

    Thanks a lot for your quick response.

    Friday, July 10, 2009 6:48 PM
  • Excellent!  Glad to hear it's working now.  I've definitely had plenty of times where I wasn't considering the different Sections that can be requested and was missing data.
    Friday, July 10, 2009 6:51 PM