473,625 Members | 2,751 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3391
On Apr 10, 1:37*am, zaldy <za...@discussi ons.microsoft.c omwrote:
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.Structure s.Model", "using Tekla.Structure s.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.In sert and Model.CommitCha nges).

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 CSharpCodeProvi der 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.00 00,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.c om.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 CSharpCodeProvi der 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 modellingstruct uresjust 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 differentstruct ures, 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 inTeklaStructur es.
Ah, that changes things. Since the code is being written by an
external application, CSharpCodeProvi der 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
CSharpCodeProvi der, create and modify a set of Compiler Parameters to
feed into your CSharpCodeProvi der, then make a Compiler Results object
and call "CompileAssembl yFromSource".

string str = "MessageBox.Sho w(\"You should import your
code into this string.\")";
CSharpCodeProvi der provider = new CSharpCodeProvi der();
System.CodeDom. Compiler.Compil erParameters cp = new
System.CodeDom. Compiler.Compil erParameters();
cp.OutputAssemb ly = "Assem1";
CompilerResults cr =
provider.Compil eAssemblyFromSo urce(cp, str);

Remember to add System.CodeDom. Compiler; and Microsoft.CShar p; 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
12721
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
7041
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 file... Thank you to all of you who can help me with this one...
19
10302
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 text is available until I have read it... which seems to imply that multiple reads of the input stream will be inevitable. Now I can correctly find the number of characters available by: |
0
1740
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 Process=Interim Level=10 Technique=Fletching Knowledge=Woodworking Device=Sawhorse Primary components=Refined Maple
1
6747
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 listen up; Reports, the way I look at them, all present data downwards, in this way; TITLE data
50
4923
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 -- the character input is a different matter, at least if I want to remain within the bounds of the standard library.
2
2476
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() { OperatingSystem os = Environment.OSVersion; AppDomain ad = Thread.GetDomain();
4
3285
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 errors. After reading the ole object from db, I saved it to C: as file1.bmp and displayed on the web. But it can not be displayed. After I manually sent the file to wordpad, it shows
4
12785
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 to read text file but could not get the data in correct format. All columns are not coming in dataset and rows are messing up. Suggestions please ???
3
2822
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 (!file.eof ()) { do {
0
8253
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8189
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8692
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8635
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8354
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8497
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4089
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2621
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1802
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.