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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics NAV (Archived)

Writing file in Client directory using DotNet Assemblies

(0) ShareShare
ReportReport
Posted on by 171

Hi All,

There is a need for development for reading and writing the file in Client directory in NAV 2013 R2 and later will be required in other versions too. Since the 'File' variable File.CREATE and WRITE functions create file in NAV Server, I am using following DOTNET assemblies:

1. DotNet System.IO.File.'mscorlib'
2. DotNet System.IO.Directory.'mscorlib'
3. DotNet System.IO.FileStream.'mscorlib'

I've also set the RunOnClient property to 'Yes' which will create the files in local directory.

However the Dotnet assembly code 'File.Create' creates the file in local directory of client, when the code to File.Write is called NAV throws a lock by another user error. Please let me know the required code, if anybody have writting a code to create file in Local directory using dot net assemblies. 

*This post is locked for comments

  • Marcellus Profile Picture
    2,735 on at

    HI Preetham,

    I would recommend you to use the File Management Codeunit 419 instead of dotnet.

    Walkthrough: Transferring a File from Microsoft Dynamics NAV Server to the Client

  • Prtham Profile Picture
    171 on at

    Thanks, But I've resolved it by myself. I will post the solution later.

    File management was not a solution to me, as it does not allow to write and read data from file.

    In short, I've created all the .Net assembly as 'RunOnClient' and did all the write and read transactions using the mscorlib class file, fileInfo , Streamwriter and StreamReader.

  • Verified answer
    Prtham Profile Picture
    171 on at

    Hi,

    The problem is resolved.

    You only need the 'DotNet System.IO.File.'mscorlib' ' to create the file in the location. It must store the return value in 'System.IO.FileStream.'mscorlib'' and then close the filestream when created. Later on, use the stream writer to write the data into file.

    In my case:

         

    CASE ProcessFileL."Character Set" OF
    
           ProcessFileL."Character Set"::ASCII:
    
               StreamWriterL := StreamWriterL.StreamWriter(OutputFileNameL,AppendFileL,EncodingL.ASCII);
    
           ProcessFileL."Character Set"::ANSI:
    
               StreamWriterL := StreamWriterL.StreamWriter(OutputFileNameL,AppendFileL,EncodingL.Default);
    
           ELSE
    
               StreamWriterL := StreamWriterL.StreamWriter(OutputFileNameL,AppendFileL,EncodingL.UTF8);
    
         END;
    
         StreamWriterL.Write(BigTextL);
    
         StreamWriterL.Close;

    where 

    StreamWriterL = DotNet : System.IO.StreamWriter.'mscorlib'.

    Do message me if anyone require further details on file handling. ;)

  • s.smith Profile Picture
    on at

    Hi,

    Any chance that You can post the source code for this ??    I have a similar issue and I cannot get the lines You show to work  -  so I guess there are more dotNet variables, etc. there needs to be used.

    If You could post a TXT version  -  cleaned for all client related  -  then it would be really great.

    Thank You so much in advance

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

Leaderboard > 🔒一 Microsoft Dynamics NAV (Archived)

#1
Hannes Holst Profile Picture

Hannes Holst 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans