473,382 Members | 1,635 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Reading a text file..

Hi!

I have a question..
How can csharp read a text file and execute it in another application? What
I mean is that, Im doing a drawing using Tekla Structures. But instead of
doing the same thing over and over again, I want to create an exe file that
allows it to read a text file and execute it in Tekla Structures. All I can
do now is to copy the contents of that text file and paste it in csharp
editor and run it, therefore I cannot compile my program.
Can anybody help me?
Thanks..
Apr 10 '08 #1
6 3361
On Apr 10, 1:37*am, zaldy <za...@discussions.microsoft.comwrote:
I have a question..
How can csharp read a text file and execute it in another application?
It's not clear to me what you mean by "execute it". Text files are
just data -
you don't "execute" them.

Is Tekla Structures an application in itself? What's its input? Could
you give more details of an example?

Jon
Apr 10 '08 #2
Hi Zaldy, Jon, I'm Qu. I'm using C# with Tekla Stuctures, so I thought
I'd join the discussion.

A quick explanation for Jon: Tekla is an external 3d modelling
program. It provides several dll files which are accessed the normal
way ("using Tekla.Structures.Model", "using Tekla.Structures.UI").
These dll files contain classes like the contour points and contour
plates above, as well as some commands to connect to the model. These
commands are run when you compile your program, and connect to the
first open Tekla document and act on it (examples are
ContourPlate.Insert and Model.CommitChanges).

The code Zaldy pasted above would compile and run straight from the C#
executable... you could paste it into Visual C# and it would work.
What he wants to do access a .txt file with it, import it, then
compile and run it. I gather you've already worked this out.

I can't find the CSharpCodeProvider class referenced in the local 2005
MSDN... is it available only to non-express users?

My approach to this problem would be more along the lines of: Create a
dynamic list of Contour Points, and several other variables (Name,
ProfileString, MaterialString, Class, etc) in a separate class, then
make your text file as a delimited file, as seen below. Extract the
variables using string functions (IndexOf, subString, and such), place
them into the constructor of your special class. Finally, get Tekla to
generate all the classes at run time.

~~~~~~~~~~~~~~~~~~
- PEDESTAL
- PL125
- SS400
- 1

~ 0.0000,100.0000,150.0000
~ 100.0000,100.0000,150.0000
~ 100.0000,0.0000,150.0000
~ etc...
~~~~~~~~~~~~~~~~~~~
Of course, you might want more flexability than this method allows, in
which case Jon's idea is much better and heaps easier...
Jun 27 '08 #3
On Apr 13, 11:04*pm, qua...@beagle.com.au wrote:

<snip>
The code Zaldy pasted above would compile and run straight from the C#
executable... you could paste it into Visual C# and it would work.
What he wants to do access a .txt file with it, import it, then
compile and run it. I gather you've already worked this out.
Yes.
I can't find the CSharpCodeProvider class referenced in the local 2005
MSDN... is it available only to non-express users?
No, it's available to everyone although it might not be in the cut-
down MSDN installed with Express. Search for it on the full MSDN - you
can still use it from Express.
My approach to this problem would be more along the lines of: Create a
dynamic list of Contour Points, and several other variables (Name,
ProfileString, MaterialString, Class, etc) in a separate class, then
make your text file as a delimited file, as seen below. Extract the
variables using string functions (IndexOf, subString, and such), place
them into the constructor of your special class. Finally, get Tekla to
generate all the classes at run time.
Yes - that does indeed sound like a better idea than having code
snippets.
Of course, you might want more flexability than this method allows, in
which case Jon's idea is much better and heaps easier...
Sort of - it really depends on who's going to be producing the text
file. Writing code outside an IDE is quite error-prone, for example.

Jon
Jun 27 '08 #4
Sort of - it really depends on who's going to be producing the text
file. Writing code outside an IDE is quite error-prone, for example.
Good point. Hey Zaldy, what are you going to place in the text files?
A database of code snippets to create specific individual objects,
variables to apply to a specific type of object, or something else?
Also important is who is going to be making the code: are you going to
code it in the IDE and copy-paste to the txt file, or is a non-
programmer going to try to write it?

Each of these would warrent a different method.

Cheers,
Qu.
Jun 27 '08 #5


"qu****@beagle.com.au" wrote:
Sort of - it really depends on who's going to be producing the text
file. Writing code outside an IDE is quite error-prone, for example.
Good point. Hey Zaldy, what are you going to place in the text files?
A database of code snippets to create specific individual objects,
variables to apply to a specific type of object, or something else?
It will be the same as the sample text Ive shown you. To tell the truth, Im
tired of modelling structures just to import it in PDS (another application)
and be used for interference checking...It will just be a code to create
specific individual objects.

Also important is who is going to be making the code: are you going to
code it in the IDE and copy-paste to the txt file, or is a non-
programmer going to try to write it?
No one will write the text file. An external application will be the one
doing that for me. Ive already tried it and its 0% error as of now. That
external application will write the text file in drive c. For different
structures, the contents of that text file will also be different. I want to
to create an compiled exe file that could read that text file and create
whats inside the text file in Tekla Structures.
Each of these would warrent a different method.

Cheers,
Qu.
Thanks.
Zaldy
Jun 27 '08 #6
It will be the same as the sample text Ive shown you. To tell the truth, Im
tired of modellingstructuresjust to import it in PDS (another application)
and be used for interference checking...It will just be a code to create
specific individual objects.

No one will write the text file. An external application will be the one
doing that for me. Ive already tried it and its 0% error as of now. That
external application will write the text file in drive c. For differentstructures, the contents of that text file will also be different. I want to
to create an compiled exe file that could read that text file and create
whats inside the text file inTeklaStructures.
Ah, that changes things. Since the code is being written by an
external application, CSharpCodeProvider seems the way to go.

http://msdn2.microsoft.com/en-us/lib...eprovider.aspx

As far as I understand it (remembering that I've never had to use it
before), you make a string containing your code, create a new
CSharpCodeProvider, create and modify a set of Compiler Parameters to
feed into your CSharpCodeProvider, then make a Compiler Results object
and call "CompileAssemblyFromSource".

string str = "MessageBox.Show(\"You should import your
code into this string.\")";
CSharpCodeProvider provider = new CSharpCodeProvider();
System.CodeDom.Compiler.CompilerParameters cp = new
System.CodeDom.Compiler.CompilerParameters();
cp.OutputAssembly = "Assem1";
CompilerResults cr =
provider.CompileAssemblyFromSource(cp, str);

Remember to add System.CodeDom.Compiler; and Microsoft.CSharp; to your
using statments

I can't really help you any further at the moment, because I'm not
sure how to call an assembly and don't have time to work it out. Good
luck, though.

Cheers,
Qu.
Jun 27 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Suresh Kumaran | last post by:
Hi All, Does anybody know the sytax in VB.NET to write the contents of a multiline text box to a text file? Appreciate help. Suresh
1
by: fabrice | last post by:
Hello, I've got trouble reading a text file (event viewer dump) by using the getline() function... After 200 - 300 lines that are read correctly, it suddenly stops reading the rest of the...
19
by: Lionel B | last post by:
Greetings, I need to read (unformatted text) from stdin up to EOF into a char buffer; of course I cannot allocate my buffer until I know how much text is available, and I do not know how much...
0
by: Eric Lilja | last post by:
Hello, I have a text file that contains a number of entries describing a recipe. Each entry consists of a number of strings. Here's an example file with only one entry (recipe): Name=Maple Quill...
1
by: Magnus | last post by:
allrite folks, got some questions here... 1) LAY-OUT OF REPORTS How is it possible to fundamentaly change the lay-out/form of a report in access? I dont really know it that "difficult", but...
50
by: Michael Mair | last post by:
Cheerio, I would appreciate opinions on the following: Given the task to read a _complete_ text file into a string: What is the "best" way to do it? Handling the buffer is not the problem...
2
by: Sabin Finateanu | last post by:
Hi I'm having problem reading a file from my program and I think it's from a procedure I'm using but I don't see where I'm going wrong. Here is the code: public bool AllowUsage() { ...
4
by: dale zhang | last post by:
Hi, I am trying to save and read an image from MS Access DB based on the following article: http://www.vbdotnetheaven.com/Code/Sept2003/2175.asp Right now, I saved images without any...
4
by: Amit Maheshwari | last post by:
I need to read text file having data either comma seperated or tab seperated or any custom seperator and convert into a DataSet in C# . I tried Microsoft Text Driver and Microsoft.Jet.OLEDB.4.0...
3
by: The Cool Giraffe | last post by:
Regarding the following code i have a problem. void read () { fstream file; ios::open_mode opMode = ios::in; file.open ("some.txt", opMode); char *ch = new char; vector <charv; while...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.