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 :
Finance | Project Operations, Human Resources, ...
Answered

Create File from Zip Stream and save in local file.

(0) ShareShare
ReportReport
Posted on by 512

Hi Guys,

I have a problem regarding the zip stream to save it in local drive.  I don't want to use the File::SendUserFile because it creates another session and not be seen by user. What I am doing to do is going to save the zip file in local drive. Do you have any idea?

Here is my code below.

 //Zip File
                    using(System.IO.MemoryStream zipArchiveStream = new System.IO.MemoryStream())
                    {
                        using (ZipArchive zipArchive = new ZipArchive(zipArchiveStream, ZipArchiveMode::Create, true))
                        {
                            ListEnumerator sb = lstSales.getEnumerator();
                            while(sb.moveNext())
                            {
                                BAMSalesOrderHeader header = sb.current() as BAMSalesOrderHeader;
                                ZipArchiveEntry dataFileEntry = zipArchive.CreateEntry(header.FileName());
                                using (System.IO.Stream dataFileEntryStream = dataFileEntry.Open())
                                {
                                    this.ReadTextInList(header, dataFileEntryStream);
                                }
                            }
                        }
                       
                        if(pathLocation != "")
                        {                       
                            
                            //File::SendFileToUser(zipArchiveStream, package   extensionZIP);
                        
                            info("Operation Successfully");
                        }
                        CodeAccessPermission::revertAssert();

Thank you so much for your help.

Regards,

CJ

I have the same question (0)
  • Blue Wang Profile Picture
    on at

    Hi CJ,

    Usually we create a download link of the zip file and sends the link to the user.

    The file is put into the temporary blob storage.

    You can take a look at this:dynamicsuser.net/.../need-to-store-a-file-stream-into-a-local-file-path-in-d365fo

  • Suggested answer
    Sergei Minozhenko Profile Picture
    23,093 on at

    Hi Christian,

    It's not possible to access local drive and save the file directly to it. You can maybe try to use FTP, Sharepoint, and so on instead of the local disk?

    Could you, please, explain what you mean by "it creates another session and not be seen by user"?

  • CJ Profile Picture
    512 on at

    Hi Sergie,

    I use the batch sysframework when consolidating the data it will create file .txt and use File::sendFiletouser but is not working.

  • Verified answer
    Sergei Minozhenko Profile Picture
    23,093 on at

    Hi Christian,

    Yes, that's true. You can't send the file to the user in batch.

    But you still have a couple of other options (some of them below):

    1. Use external shared services (like ftp, OneDrive, Sharepoint)

    2. Document management, attach a file to some record if possible. Also, you can add a notification for users when the file is ready ( docs.microsoft.com/.../messaging-api-center-bar-details )

    3. Send by e-mail

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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 611 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 529 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 285 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans