Undocumented "feature" of DOWNLOADFROMSTREAM?

rocatisrocatis Member Posts: 163
edited 2013-03-21 in NAV Three Tier
The setup is the following: standard 6.01 demo installation, running both the Classic Client and RTC on the same machine (not optimal, I know).

Make the following changes to function BLOBExport in codeunit 419 "3-Tier Automation Mgt.":
MESSAGE('Before calling DOWNLOADFROMSTREAM\Path=[%1]\ToFile=[%2]',path,tofile);  // Debug
  DOWNLOADFROMSTREAM(NVInStream,Text006,Path,Text009,ToFile);
  MESSAGE('After calling DOWNLOADFROMSTREAM\Path=[%1]\ToFile=[%2]',path,tofile);  // Debug
I call the function using this bit of code:
ThreeTierAutomationMgt.BLOBExport(TempBlob,'c:\test.txt',FALSE));
The expected result is that the (text) file contained in TempBlob.Blob is exported as test.txt in c:\ of the RTC (which, incidentally is the same as c:\ of my Classic Client). However, running the code yields these results:

Before calling DOWNLOADFROMSTREAM
Path=[<TEMP>]
ToFile=[test.txt]

After calling DOWNLOADFROMSTREAM
Path=[<TEMP>]
ToFile=[C:\Documents and Settings\brocatis3101\Local Settings\Temp\Microsoft Dynamics NAV\3868\__TEMP__3bcc9a646f464b00be8c4eaca47f5bc5.txt]


So the ToFile parameter is modified by the DOWNLOADFROMSTREAM command. This is not documented anywhere (what a surprise :shock: ). Thing is, the parameter is only changed if the Path parameter is set to "MagicPath" (<TEMP>) which apparently is the secret way to avoid the "Save As" dialog (again, undocumented).

I want to save the file with the filename I supply, but without opening the "Save As" dialog. How do I do that?
Brian Rocatis
Senior NAV Developer
Elbek & Vejrup

Comments

  • mihail_kolevmihail_kolev Member Posts: 379
    The RTC exports to the Service machine, and I guess for RTC this is the TEMP directory... :roll:
    -Mihail- [MCTS]
  • rocatisrocatis Member Posts: 163
    The RTC exports to the Service machine, and I guess for RTC this is the TEMP directory... :roll:

    Yes and no. The real problem is that it seems that the only way to bypass the user dialog is to specify "<TEMP>" as the path - and that in turn results in the file being saved in the folder specified by the TEMP environment variable.

    It look decidedly dodgy :thumbsdown:
    Brian Rocatis
    Senior NAV Developer
    Elbek & Vejrup
  • rocatisrocatis Member Posts: 163
    rocatis wrote:
    I want to save the file with the filename I supply, but without opening the "Save As" dialog. How do I do that?
    I think I know what's going on here: the DOWNLOADFROMSTREAM function is only allowed to save files at specific locations on the RTC when the user manually selects that location in a dialog box. The reason for this is that the server has no conception of the file structure (if any!) on the RTC. When developing on the RTC I should ignore the fact that (for the moment) I know that the RTC is running on a Windows pc that most likely will have a C: drive.

    For this reason, the RTC should decide where to download files when then dialog box is bypassed.

    That fact that the method for bypassing the dialog box has been implemented in such a clumsy, undocumented and downright “un-NAV” way is just unfortunate.
    Brian Rocatis
    Senior NAV Developer
    Elbek & Vejrup
  • Ian_Piddington10199Ian_Piddington10199 Member Posts: 167
    Has anyone figured out a way to get round this? I have a simialr problem with the DOWNLOAD.

    I have generated a text file on the service tier and need to move it to a network share without the user having to select the file path.

    The customer wants specific people to be able to generate a electronic funds payment file but they don't want them to be able to access it after it has been generated. the actual passing of the file to the banking software is handled by someone else with enough permission to read the file.

    Effectively the user that will crete the file has write only permission on the network share. However I cannot suppress the save path box. I have also tried setting the file to be generated directly to the desired path instead of on the service tier but that also fails.

    Regards

    Ian
    Regards

    Ian
  • kinekine Member Posts: 12,562
    I think that the path do do that is to save it into TEMP folder (to not display the dialog) and than rename it from the autogenerated name to the real name and path you want...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • mohana_cse06mohana_cse06 Member Posts: 5,504
  • Ian_Piddington10199Ian_Piddington10199 Member Posts: 167


    I hadn't but I have now :).

    I think it has solved the problem.

    Many thanks
    Regards

    Ian
  • BeliasBelias Member Posts: 2,998
    this is my bible for this kind of problems, but it's been a while since i've used the download function the last time. Probably it's outdated :-k
    http://blogs.msdn.com/b/nav-reporting/archive/2009/10/08/send-email-with-pdf-attachment-in-nav-2009.aspx
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • Ravi_Prakash_GoyalRavi_Prakash_Goyal Member Posts: 72
    I am also facing same issue with DOWNLOADFROMSTREAM. Is this a bug?

    DOWNLOADFROMSTREAM(NVInStream,Text006,Path,Text009,ToFile);

    For a workaround can I set the 'Path' parameter to the 'ToFile' directory path. Will it resolve the issue? Or it may lead into other issues?

    @rocatis : Did you figure out the way to resolve it? Please let me know. Thanks.
  • mohana_cse06mohana_cse06 Member Posts: 5,504
    Do you want to save it without save as window?
  • Ravi_Prakash_GoyalRavi_Prakash_Goyal Member Posts: 72
    Yes, you are right. I want to save file at defined location without opening pop up window.
  • Ravi_Prakash_GoyalRavi_Prakash_Goyal Member Posts: 72
    I debugged the code and actually I am getting dialog window during BLOB Import i.e. UPLOADINTOSTREAM function in BLOBImport() in CU 419.

    I have rewritten new function called BLOBImportWOCommDialog which will download my server file to client Temp folder (i.e. Magicpath (<TEMP>)) and then upload it .
        PROCEDURE BLOBImportWOCommDialog@1170000000(VAR BLOBRef@1000 : TEMPORARY Record 99008535;Name@1002 : Text) : Text;
        VAR
          NVInStream@1001 : InStream;
          NVOutStream@1004 : OutStream;
          UploadResult@1006 : Boolean;
          ErrorMessage@1007 : Text;
          FileSystemObject@1170000000 : Automation "{F935DC20-1CF0-11D0-ADB9-00C04FD58A0B} 1.0:{0D43FE01-F093-11CF-8940-00A0C9054228}:'Windows Script Host Object Model'.FileSystemObject";
          Path@1170000003 : Text[1024];
          FileVar@1170000005 : File;
          TempFolder@1170000006 : Text[1024];
          FileToUpload@1170000007 : Text[1024];
          FolderName@1170000008 : Text[1024];
          TempFileName@1170000001 : Text[1024];
          FileExtension@1003 : Text;
        BEGIN
          CLEARLASTERROR;
    
          //Commented standard code
          //UploadResult := UPLOADINTOSTREAM(Text007,'',Text009,Name,NVInStream); 
    
          FileToUpload := Name;  //Added New Line
          FileToUpload := DownloadTempFile(FileToUpload);  //Added New Line
    
          UploadResult := UPLOADINTOSTREAM('',Magicpath,'',FileToUpload,NVInStream);  //Added New Line
          IF UploadResult THEN BEGIN
            BLOBRef.Blob.CREATEOUTSTREAM(NVOutStream);
            COPYSTREAM(NVOutStream,NVInStream);
    
            EXIT(Name);
          END;
    
          ErrorMessage := GETLASTERRORTEXT;
          IF ErrorMessage <> '' THEN
            ERROR(ErrorMessage);
    
          EXIT('');
        END;
    

    I called above function from my code as below:

    FileName := FileMgt.BLOBImportWOCommDialog(TempBlob,lFile);
    IF FileName <> '' THEN
    lLoggLine.FileData := TempBlob.Blob;
    lLoggLine.MODIFY;

    It worked successfully without popping out dialog window as I am uploading file from local <TEMP> folder.
Sign In or Register to comment.