Finding Server Side files

Mikael_Smith_LarsenMikael_Smith_Larsen Member Posts: 7
edited 2012-08-22 in NAV Three Tier
Hi Everybody

I have a problem with finding files on the Server. What I from the start wanted to do, was to copy a file in the TEMPORARYPATH to new name so that I could attach a file with more a meaningful name to an eMail, but the function: WshFileSystemObject.FileExists(txtSrcFileName) all was returns false.

How can this be done in Nav2013?

I have made 2 pieces of test code that runs on R2 and on Nav2013, in the R2 I can find the file, but not on the Nav2013 file isn’t found.

Nav2009 R2
// Var : WshFileSystemObject	Automation	'Windows Script Host Object Model'.FileSystemObject	

txtSrcFileName := TEMPORARYPATH + 'Source.txt'; // The file Source.txt does exists in the Temp Folder for the R2 server
txtNewFileName := TEMPORARYPATH + 'Target.txt';

CREATE(WshFileSystemObject,TRUE, FALSE); // Created with Server Side Parameters

IF WshFileSystemObject.FileExists(txtSrcFileName) THEN
  MESSAGE('Wsh File fonnd : %1', txtSrcFileName); // The message is shown, since the is fond on the Server


Nav2013 Beta
// Var : WshFileSystemObject	Automation	'Windows Script Host Object Model'.FileSystemObject	
//         FileHelper	             DotNet               	System.IO.File.'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'

txtSrcFileName := TEMPORARYPATH + 'Source.txt';  // The file Source.txt does exists in the Temp Folder for the NAV2013 Server

CREATE(WshFileSystemObject,TRUE,TRUE);  // Created with Client Side Parameters
IF WshFileSystemObject.FileExists(txtSrcFileName) THEN
  MESSAGE('Wsh File Found : %1',txtSrcFileName);  // The message is Never shown

IF FileHelper.Exists(txtSrcFileName) THEN
  MESSAGE('DotNet File Found : %1',txtSrcFileName); // The message is Never shown

Hoping someone can help.

Best regards
Mikael Smith Larsen

Comments

  • AvallackAvallack Member Posts: 18
    Try this :
    FileHelper : dotnet : System.IO.File.'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
    Bool := FileHelper.Exists("you file") with RunOnClient properties = False


    Avallack.
    Navision Technical Consultant & .Net Developer
  • Troubles_In_ParadiseTroubles_In_Paradise Member Posts: 588
    Hi Everybody
    Nav2013 Beta
    // Var : WshFileSystemObject Automation 'Windows Script Host Object Model'.FileSystemObject 
    // FileHelper DotNet System.IO.File.'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
    
    txtSrcFileName := TEMPORARYPATH + 'Source.txt'; // The file Source.txt does exists in the Temp Folder for the NAV2013 Server
    
    CREATE(WshFileSystemObject,TRUE,TRUE); // Created with Client Side Parameters
    IF WshFileSystemObject.FileExists(txtSrcFileName) THEN
    MESSAGE('Wsh File Found : %1',txtSrcFileName); // The message is Never shown
    
    IF FileHelper.Exists(txtSrcFileName) THEN
    MESSAGE('DotNet File Found : %1',txtSrcFileName); // The message is Never shown
    

    Maybe I miss something but.. if your file is on NAV2013 server why do you create your automation on Client?
    Another question... which is the value of the property "RunOnClient" of your FileHelper variable?
    ~Rik~
    It works as expected... More or Less...
  • deV.chdeV.ch Member Posts: 543
    NAV2013 Server runs 64bit so therefore COM Automation does not work, i guess RunOnClient is always True so using Automation on server is not possible, Use DotNet Interop (As already suggested) instead.

    But Since you create your Automations with RunOnClient = TRUE anyway this can't have worked previously on NAV2009, you explicitly instanciate the object on the client by yourself.

    And last one: why don't you just use EXISTS() Function, it's always executed on the server, so this should give expected result.
  • Hi Everybody

    Thanks for the answers they were very helpful.

    The solution for me was to use the DotNet: System.IO.File.'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' and set the Property: RunOnClient=No. After that it all works fine. :D

    Regarding the Creating of the Automation variable: WshFileSystemObject, the function CREATE() is changed in Nav2013 so it is only allow to create objects on the Client.

    Once Again Thanks

    Mikael Smith Larsen
  • AvallackAvallack Member Posts: 18
    Hi Everybody

    Thanks for the answers they were very helpful.

    The solution for me was to use the DotNet: System.IO.File.'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' and set the Property: RunOnClient=No. After that it all works fine. :D

    Regarding the Creating of the Automation variable: WshFileSystemObject, the function CREATE() is changed in Nav2013 so it is only allow to create objects on the Client.

    Once Again Thanks

    Mikael Smith Larsen

    You can use au dotnet var instead of automation ... it's has been method from Navision 2013 =)
    Navision Technical Consultant & .Net Developer
Sign In or Register to comment.