RSS

Dynamics NAV 2009 R2: DotNet System.String

21 Sep

If you are having the need to use DotNet in an older client such as Dynamics NAV 2009 R2 you will problably run into troubles which they have fixed for later versions of Dynamics NAV.  I had the problem that I tried to downgrade code using the DotNet type System.String. I didn’t get very far until the compiler started to complain…

I can’t assign any values to my variable. Instead I get “Assignment is not allowed for this variable“. Hmmm.. But then I tried to use another methods to add values to my System.String variable.

I looked at the System.String on msdn and found the method Insert. So how about Variable.Insert(0, <MyString>) ?
Unfortunately that didn’t work either. The error I received was “The DotNet variable has not been instantiated“.

Okay, how about using the constructors? Well that didn’t work either. The solution became to use StringBuilder instead (System.Text.StringBuilder). I could use that as a string container and it also had the method that I was looking for in the first place, Replace.

So I replaced my Original code:

DotNetSystemString := DotNetSystemIOFile.ReadAllText(FileName);
DotNetSystemString := DotNetSystemString.Replace('OldText','NewText');
DotNetSystemIOFile.WriteAllText(FileName,DotNetSystemString.ToString);

With:
DotNetSystemTextStringBuilder := DotNetSystemTextStringBuilder.StringBuilder(DotNetSystemIOFile.ReadAllText(FileName));
DotNetSystemTextStringBuilder.Replace('OldText','NewText');
DotNetSystemIOFile.WriteAllText(FileName,DotNetSystemTextStringBuilder.ToString);

I hope that helps you.

 
Leave a comment

Posted by on 2015-09-21 in Okategoriserade

 

Tags: , , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

 
James Pearson

Thoughts about Microsoft Dynamics 365 Business Central / NAV development

Roberto Stefanetti NAV & Business Central Blog

Microsoft Dynamics 365 MVP, Microsoft Dynamics NAV and Microsoft Dynamics 365 Business Central News

JoeBrown

DevOps starts with culture!

Comments for DevOps ABCs Blog

Reflections from the ERP field

DevOps ABCs Blog

Reflections from the ERP field

Dynamics 365 Business Central for Partners

Reflections from the ERP field

Freddys blog

Learn something new... - then Teach someone!

Stefano Demiliani Technical Blog

Reflections from the ERP field

David Worthington's NAV Performance Blog

Micosoft Dynamics NAV Performance Testing & Optimization

Freddys Blog

Reflections from the ERP field

Mark Brummel Blog | Microsoft Dynamics NAV

Master Classes Design Patterns and more...

Vjeko.com

ideas in the cloud

Goprowe AB

Reflections from the ERP field

ArcherPoint Developer Blog

Reflections from the ERP field

The NAV Viking´s Blog

- Sharing my experience in the Dynamics NAV world

Comments for

Reflections from the ERP field

Nav Can Be Fun

Its Really Fun to Work with Microsoft Dynamics Nav / D365 Business Central

Navision-Girl.Com

Reflections from the ERP field

%d bloggers like this: