Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 Community / Forums / Finance forum / XML file not uploading...
Finance forum
Suggested answer

XML file not uploading to blob

Posted on by 207
Hi All,
 
I am trying to upload my xml to blob storage. It is getting uploaded but the file size is 3B. I am suspecting the stream has null value sue to which the xml is not appearing.
Please find the below code I have written.
  streamIO.write(xmlDoc);
 
  XX_VendPaymIntegrationHelper::uploadToBlob(parameters.BlobStorageConnectionString,
                                              parameters.BlobStorageContainer,
                                             parameters.BlobStorageOutboundFolder,
                                             fileName,
                                             streamIO,xmlDoc);
 
  public static void uploadToBlob(HS_VendPaymIntBlobStorageConnectionString _connectionString,
                                     HS_VendPaymIntBlobStorageContainer _container,
                                     HS_VendPaymBlobStorageOutboundFolder _folder,
                                     Filename _filename,
                                     CommaTextStreamIo _streamIO, XMLDocument _xmlDoc )
  {
      try
      {
          CloudStorageAccount storageAccount = Microsoft.WindowsAzure.Storage.CloudStorageAccount::Parse(_connectionString);
          CloudBlobClient     blobClient = storageAccount.CreateCloudBlobClient();
          CloudBlobContainer  blobContainer = blobClient.GetContainerReference(_container);
          //blobContainer.CreateIfNotExists(null, null); //create blob container

          Filename            fullName = _folder ? _folder + "/" + _filename : _filename;
          CloudBlockBlob      destBlob = blobContainer.GetBlockBlobReference(fullName);
          System.IO.MemoryStream memstream = _streamIO.getstream();
          destBlob.UploadFromStream(memstream, null, null, null);

          
      
      }
      catch
      {
          throw error("Blob error");
      }
  }
 
 
Please help.
 
Thanks,
Priya
  • Suggested answer
    Martin Dráb Profile Picture
    Martin Dráb 228,706 Most Valuable Professional on at
    XML file not uploading to blob
    You may mean either the X++ class XMLDocument or .NET class System.Xml.XmlDocument. In either case, writing the object reference to a stream is wrong.
     
    Use writeTo() method of the document object instead.
     
    For example:
    System.IO.MemoryStream stream = new System.IO.MemoryStream();
    
    XmlWriter xmlWriter = XmlWriter::newStream(stream);
    
    xmlDoc.writeTo(xmlWriter);
    writer.flush();
  • PriyaDutta Profile Picture
    PriyaDutta 207 on at
    XML file not uploading to blob
    Hi Martin,
     
    I debugged the code and Length is= 3
    Xmldoc is of XMLDocument datatype.
     
  • Martin Dráb Profile Picture
    Martin Dráb 228,706 Most Valuable Professional on at
    XML file not uploading to blob
    You should do more work on the the problem isolation, instead of just trying random pieces of code. For instance, you said you might have no data written to _streamIO. If it's the case, resetting the position won't help you - it won't change the fact that you haven't written anything to the stream. But maybe your assumption is wrong and you actually have data there. You should test the assumption, e.g. by looking at the Length property of the stream.
     
    Regarding your question about streamIO.write(xmlDoc), what is the data type of your xmlDoc variable?
  • PriyaDutta Profile Picture
    PriyaDutta 207 on at
    XML file not uploading to blob
    Hi Martin, 
    I have tried adding position=0 but same issue.
     try
     {
         CloudStorageAccount storageAccount = Microsoft.WindowsAzure.Storage.CloudStorageAccount::Parse(_connectionString);
         CloudBlobClient     blobClient = storageAccount.CreateCloudBlobClient();
         CloudBlobContainer  blobContainer = blobClient.GetContainerReference(_container);
         //blobContainer.CreateIfNotExists(null, null); //create blob container
    
         Filename            fullName = _folder ? _folder + "/" + _filename : _filename;
         CloudBlockBlob      destBlob = blobContainer.GetBlockBlobReference(fullName);
         System.IO.MemoryStream memstream = _streamIO.getstream();
         memstream.Position = 0;
         destBlob.UploadFromStream(memstream, null, null, null);
    
         
     
     }
    The question is it this the correct way to write to stream ?  Is there any alternative to convert the xml file to stream ?
    streamIO.write(xmlDoc);
    And I am using D365FO.
  • Martin Dráb Profile Picture
    Martin Dráb 228,706 Most Valuable Professional on at
    XML file not uploading to blob
    Well, if you suspect that _streamIO is empty, test it. We can't do it for you; you're the only one who can run your complete code.
     
    By the way, it's possible that you've written data successfully to the stream but it's object is pointing to the end of the stream, therefore you need to reset the position to the beginning of the stream. It may be as simple as assigning 0 to the Position property (depending on the type of the stream).
     
    By the way, which version of AX is it about?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,572 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,706 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans