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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

how to download stream from url to local folder in d365 using x++

(0) ShareShare
ReportReport
Posted on by 960

Hi all,

I am having a word document uploaded to the temporary url. i want to download the document from the url to my local folder(folder creation using x++).

7506.Untitled1.jpg

i am using FileUploadTemporaryStorageResult result = File::SendFileToTempStore_GetResult to generate the url.

if i use browser.navigate in my job. it's downloading automatically in "Downloads" folder in system . i want to create my own folder and then save/download the document there

Any suggestions plss

I have the same question (0)
  • WillWU Profile Picture
    22,363 on at

    Hi Test Bot,

    Have you tried file::sendFileToUser(stream,filePathAndName).

  • Suggested answer
    nmaenpaa Profile Picture
    101,172 Moderator on at

    Hi Test_Bot,

    D365 can't see or create any folders on your workstation, just like any other websites (luckily) can't. The system can just ask the browser to open a download dialog, and from there on it's up to the browser and the user to choose a location that they want.

    You can set up the default download folder in your browser's settings.

  • TestBot Profile Picture
    960 on at

    Hi Wil Wu,

    In that method parameters, its given as only _filename. how can store/addmy local folder path. any example code or reference

    public static void SendFileToUser(System.IO.Stream stream, str fileName, ClassName fileUploadStrategyClassName = classstr(FileUploadTemporaryStorageStrategy))

       {

       }

  • WillWU Profile Picture
    22,363 on at

    Hi partner,

    I don't have an environment to test for you right now, please check this blog, you can try pass the full path in the second parameter.

    shootax.blogspot.com/.../x-d365fo-create-temp-file-and-save-to.html

  • TestBot Profile Picture
    960 on at

    Hi Wil Wu,

    I hav tried. but didn't got succceeded. can u provide any other suggestions.

  • Martin Dráb Profile Picture
    240,540 Most Valuable Professional on at

    As Nikolaos explained, what you're trying to do isn't possible. The web server doesn't have access to files on client machines.

  • Suggested answer
    Sankar Ramalingam Profile Picture
    264 on at

    As a workaround, you could make your local folder to FTP and drop the file from D365 using below code.

    System.Byte[] bytes;
    System.Text.Encoding getUTF8;
    getUTF8 = System.Text.Encoding::get_UTF8();
    System.Object request,response,credential;
    System.Net.FtpWebRequest ftpRequest;
    System.IO.Stream requestStream;
    
    System.IO.StreamReader streamReader = new System.IO.StreamReader(stream);
    bytes = getUTF8.GetBytes(streamReader.ReadToEnd());
    
    request = System.Net.WebRequest::Create(new System.Uri("FTPURL"));
    ftpRequest = request; //Type casting object to ftpwebrequest object
    credential = new System.Net.NetworkCredential("UserName", "Password");
    ftpRequest.set_Credentials(credential);
    ftpRequest.set_ContentLength(bytes.get_Length());
    
    ftpRequest.set_Method('STOR');
    
    requestStream = ftpRequest.GetRequestStream();
    requestStream.Write(bytes,0,bytes.get_Length());
    requestStream.Close();

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 345 Most Valuable Professional

#2
CU10121822-0 Profile Picture

CU10121822-0 304

#3
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 283 Super User 2026 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans