web
You’re offline. This is a read only version of the page.
close
Skip to main content
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

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

  • WillWU Profile Picture
    on at
    RE: how to download stream from url to local folder in d365 using x++

    Hi Test Bot,

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

  • Suggested answer
    nmaenpaa Profile Picture
    on at
    RE: how to download stream from url to local folder in d365 using x++

    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
    on at
    RE: how to download stream from url to local folder in d365 using x++

    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
    on at
    RE: how to download stream from url to local folder in d365 using x++

    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
    on at
    RE: how to download stream from url to local folder in d365 using x++

    Hi Wil Wu,

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

  • Martin Dráb Profile Picture
    on at
    RE: how to download stream from url to local folder in d365 using x++

    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
    on at
    RE: how to download stream from url to local folder in d365 using x++

    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

Responsible AI policies

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

Pallavi Phade – Community Spotlight

We are honored to recognize Pallavi Phade as our Community Spotlight honoree for…

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

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans