web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Import images to document handling

(0) ShareShare
ReportReport
Posted on by 650

I have managed to get to the point where I can get a stream created from my file from url.  Having trouble figuring out how I can create the docuref and docuvalue table records from my stream.  I have debugged the DocumentUpload form however the critical part of code is handled by the Uploadcontrol and I can't seem to get to the code that is actually sending the file to azure and getting back an id.

I have also looked at DocumentFileHelper::attachDocumentAsUser() however I'm having an issue with it wanting a string for documentcontents.  Does anyone have an example of this being used to attach a jpeg?

Here is my code that generates the stream:

public void importFile()

{

System.IO.Stream newImage;

FileUploadTemporaryStorageResult result;

FileUploadTemporaryStorageStrategy strategy = new FileUploadTemporaryStorageStrategy();

//FileUploadTemporaryStorageResult result = File::GetFileFromUser() as FileUploadTemporaryStorageResult

//newImage = File::UseFileFromURL("C:\\Users\\axlocaladmin\\Downloads\\zhp710_P2.jpg");// as FileUploadTemporaryStorageResult;

newImage = File::UseFileFromURL("C:\\Users\\Public\\Documents\\zhp710_P21.jpg");

//result = strategy.uploadFile(newImage,"zhp710_P2","image/jpeg","jpg");

//File::SendFileToUser(newImage,"zhp710_P2","FileUploadTemporaryStorageStrategy");

}

You can see that I've played around with various options to no avail.

 

Thanks,

Don

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Martin Dráb Profile Picture
    237,878 Most Valuable Professional on at

    You can use DocumentManagement.attachFile() (one of its arguments is a stream).

  • Suggested answer
    Don Shields Profile Picture
    650 on at

    It looks like that will work.  I was attemping to use DocumentFileHelper.attachDocumentAsUser() but DocumentManagement::AttachFile() appears to work and be easier to manage.

  • Don Shields Profile Picture
    650 on at

    This method is working.  I am able to get the proper DocuRef and DocuValue records created with this method using this line of code:

    DocuRef = DocuManagement::AttachFile(tablenum(InventTable),22565437142,curExt(),'Image',newImage,'image.jpg','Image','image.jpg','image notes'); where "newImage" is the file stream.  I am able to print the image on my report however.  

    My only issue is that the preview in Document management doesn't work.  I am able to open the image so I assume it is stored properly.  Thanks for the input.  I will debug further tomorrow to try and discover why the preview doesn't work.

  • Mea_ Profile Picture
    60,284 on at

    Hi Don Shields,

    File::UseFileFromURL("C:\\Users\\Public\\Documents\\zhp710_P21.jpg"); works great with local files, but how are you going to use it in production environment ?

  • Suggested answer
    Mea_ Profile Picture
    60,284 on at

    To attach image use next code 

    DocuRef docuRef = DocumentManagement::attachFile(
                             inventTable.TableId,
                             inventTable.RecId,
                             curext(),
                             DocuType::typeImage(),
                             memoryStream,
                             fileName,
                             null,
                             description);
                            
    if (docuRef)
    {
        EcoResProductImage::create(docuRef);
    }


  • Don Shields Profile Picture
    650 on at

    Yes that part of the code works.  I am actually already using the EcoResProdcutImage::create and that works as well.  As you said, File::UseFileFromURL("C:\\Users\\Public\\Documents\\zhp710_P21.jpg");  Works with the local drive.  In production I will have to have an actual URL.  I'm still working on that part.  

  • Mea_ Profile Picture
    60,284 on at

    I recently did similar modification and used Azure File storage for files, so users simply dumped files to file share and provide a spreadsheet where they mapped itemId to file path. It's quite easy to change code from File::UseFileFromURL to CloudFile.DownloadToStream, you can read about here 

  • Don Shields Profile Picture
    650 on at

    That looks like what I had in mind.  I'm going to give it shot.  I'll post back the results.  Thanks!

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Priya_K Profile Picture

Priya_K 4

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#3
Ali Zaidi Profile Picture

Ali Zaidi 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans