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.

Advertisements
 
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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

 
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 waldo's blog

Reflections from the ERP field

Nav Can Be Fun

Its Really Fun to Work with Microsoft Dynamics Nav

Navision-Girl.Com

Reflections from the ERP field

LET'S TALK NAV

Tips, Tricks, How-To's & News about Microsoft Dynamics NAV & Dynamics 365 for Financials

Kine's Info

Reflections from the ERP field

blog.wibeck.org/

Just another WordPress.com site

NAV/SQL Performance - My Two Cents

Reflections from the ERP field

Hougaard.com – Applied Hacking

Reflections from the ERP field

Kauffmann @ Dynamics NAV

Reflections from the ERP field

Kriki’s Dynamics NAV blog

Reflections from the ERP field

Rashed Amini

Reflections from the ERP field

Olof Simren - Microsoft Dynamics NAV Blog

My blog about Microsoft Dynamic NAV tips and tricks. Remember to Subscribe!

Van Vugt's dynamiXs

Reflections from the ERP field

Navisionary – Dynamics NAV

Reflections from the ERP field

%d bloggers like this: