GetItemXml of File Class RRS feed

  • Question

  • Hi,

    I am using below code to get data filled in File class of Microsoft.Health and upload it to HV, I have to use GetItemXml since this is in webservice and had to make it serializable. Is there any alternative available or anything wrong in my code?

                    Microsoft.Health.ItemTypes.File file = new Microsoft.Health.ItemTypes.File();
                    string path = filePath;
                    file.SetContent(path, new CodableValue("text/txt"));
                    BlobStore blobStore = file.GetBlobStore((HealthRecordAccessor)null);

                    byte[] fileContent = file.Content;

                    Blob blob = file.GetBlobStore((HealthRecordAccessor)null).NewBlob(string.Empty, file.ContentType.ToString());
                    string itemXml=file.GetItemXml();

                    XmlDocument xDoc = new XmlDocument();
                    XmlNode xNode= xDoc.SelectSingleNode("//file");

                    Guid recordTypeGuid= new Guid("9c48a2b8-952c-4f5a-935d-f3292326bf54");

                    HealthRecordItem healthRecord = new HealthRecordItem(recordTypeGuid, xNode);


    This code is working for all the other classes whereas it gives below error for file class, even when the xml generated has thing element in it.

    Invalid xml for thing. The 'urn:com.microsoft.wc.thing.file:thing' element is not declared. -- The 'urn:com.microsoft.wc.thing.file:thing' element is not declared.

    mgh sols
    Wednesday, August 17, 2011 3:18 AM

All replies

  • You are trying to use the typeid for CCR to upload a file, which is why you are getting that error.

    The way you are recreating the item will not work; it will give you an item without any associated blob data. I think that if you use ItemTypeManager.DeserializeItem(), you will get the whole item back.

    Friday, August 19, 2011 5:25 PM