Delete file on Client

lollygaglollygag Member Posts: 7
edited 2011-11-02 in NAV Three Tier
Hi

Here is my problem.

User wants to link a file on their pc (using the RTC).
When link is saved the file is uploaded to the server, and the link is changed.
File on the client needs to be deleted.

I have sucessfully (after lots of trial and error) managed to upload the file and change the URL in the link. However I cannot seem to delete the original file from the client.

Any ideas greatly appriciated...

Answers

  • mdPartnerNLmdPartnerNL Member Posts: 802
    Yes, this RTC client is strange in a way.

    Could you show how you did the upload and change? I want to do something simular. I have some code for the delete on the client. Will let you know tomorrow.
  • Rob_HansenRob_Hansen Member Posts: 296
    You can create an instance of the FileSystemObject on the client side through automation and use it to delete the file.
  • lollygaglollygag Member Posts: 7
    Hi

    How do I create an instance of the FileSystemObject on the client side?

    I can see this option for dotNet but not Automation. And I only see the FileSystemObject as an automation.

    Am I missing something really obvious? :oops:
  • lollygaglollygag Member Posts: 7
    mdPartnerNL..

    here is a link to the blog that got me this far.

    http://blogs.msdn.com/b/nav/archive/201 ... g-box.aspx
  • mdPartnerNLmdPartnerNL Member Posts: 802
    @lollygag
    Could you show me the NAV source code of what you did?
        PROCEDURE EraseOnClient@1000000023(VAR vPtFileNamePath@1000000001 : Text[1024]);
        VAR
          LaScriptControl@1000000003 : Automation "{0E59F1D2-1FBE-11D0-8FF2-00A0D10038BC} 1.0:{0E59F1D5-1FBE-11D0-8FF2-00A0D10038BC}:'Microsoft Script Control 1.0'.ScriptControl";
          CR@1000000002 : Text[1];
        BEGIN
          IF ISSERVICETIER THEN BEGIN
            IF CREATE(LaScriptControl,TRUE,TRUE) THEN BEGIN
                CR := ' '; CR[1] := 13;
                LaScriptControl.Language := 'VBScript';
                LaScriptControl.AddCode(
                'set fso = createobject("Scripting.FileSystemObject")'+CR+
                ''+CR+
                'function FileDelete(thisFile)'+CR+
                'if fso.FileExists(thisFile) then'+CR+
                '  fso.DeleteFile thisFile'+CR+
                'end if'+CR+
                'end function');
                LaScriptControl.Eval('FileDelete("'+vPtFileNamePath+'")');
            END;
          END ELSE BEGIN
            IF EXISTS(vPtFileNamePath) THEN BEGIN
              ERASE(vPtFileNamePath);
            END;
          END;
        END;
    

    Haven't tested it yet. Will do later this day when opening my project
  • lollygaglollygag Member Posts: 7
    Thank you mdPartnerNL, that works great. Below is the code you requested.
    I hope this helps.
    MoveRTC()
    FileToUpload := GetFilename(URL1);
    FolderName := GetFoldername(URL1);
    
    PurchSetup.GET;
    PurchSetup.TESTFIELD("Attachment Sharename");
    
    FileVar.CREATETEMPFILE;
    FileVar.CREATEINSTREAM(IStream);
    DOWNLOADFROMSTREAM(IStream,'','<TEMP>', '',MagicPath);
    FileVar.CLOSE;
    
    FOR i := STRLEN(MagicPath) DOWNTO 1 DO BEGIN
      IF MagicPath[i] = '\' THEN BEGIN
        MagicPath := COPYSTR(MagicPath,1,i);
        i := 1;
      END;
    END;
    
    IF ISCLEAR(FileSystemObject) THEN CREATE(FileSystemObject,TRUE,TRUE);
    
    FileSystemObject.CopyFile(FolderName + '\' + FileToUpload,MagicPath + '\' + FileToUpload);
    
    UPLOADINTOSTREAM('','<TEMP>','',FileToUpload,IStream);
     
    NewFilepath := PurchSetup."Attachment Sharename" + GetFilename(URL1);
    
    FileVar.WRITEMODE(TRUE);
    FileVar.CREATE(NewFilepath);
    FileVar.CREATEOUTSTREAM(OStream);
    COPYSTREAM(OStream,IStream);
    FileVar.CLOSE;
    
    URL1 := NewFilepath;
    IF MODIFY THEN;
    
    GetFilename(str1 : Text[250]) : Text[250]
    WHILE STRPOS(str1,'\') > 0 DO BEGIN
      i+=1;
      str1 := COPYSTR(str1,STRPOS(str1,'\')+1);
      IF i > 50 THEN ERROR('');
    END;
    EXIT(str1);
    
    GetFoldername(str1 : Text[250]) : Text[250]
    FOR i := STRLEN(str1) DOWNTO 1 DO BEGIN
      IF str1[i] = '\' THEN BEGIN
        str1 := COPYSTR(str1,1,i);
        i := 1;
      END;
    END;
    EXIT(str1 + '\');
    
  • mdPartnerNLmdPartnerNL Member Posts: 802
    and thank you. I like sharing :D
Sign In or Register to comment.