I have the following .cs file: Hope you can read the code
In the Main() I want to pass the PathName and FileName and have the
FileStream object do a read, and return it into a string.
I can get intellisense to recognize Source.ReadSourceFile, but I haven't
figured out away to pass the parameters with this call in the Main():
string Test = Source.ReadSourceFile.Read("C:\\MyFile\\", "TestDir.txt");
Here it is:
using System;
using System.IO;
namespace Source
{
/// <summary>
/// Summary description for Class1.
/// </summary>
public class ReadSourceFile
{
public string Read(string PathName, string FileName)
{
System.IO.FileStream file = new System.IO.FileStream(PathName + FileName,
System.IO.FileMode.Open, FileAccess.Read);
StreamReader sr = new StreamReader(file);
string s = sr.ReadToEnd();
return s;
}
} }
public class main
{
string Test = Source.ReadSourceFile.Read("C:\\MyFile\\", "TestDir.txt");
}
///End code here
Any help would be appreciated!
Barry 6 985
hi barry ,
you can do it using
static void Main(string[] args)
The parameter of the Main method is a string array that represents the
command-line arguments. Usually you check for the existence of the arguments
by testing the Length property
if (args.Length == 0)
error "Please enter arguments"
else
access the arguments using args[0],args[1]..and so on
regards
Ansil
Dimensions
Technopark
Trivandrum an****@gmail.com
"Barry Young" wrote: I have the following .cs file: Hope you can read the code
In the Main() I want to pass the PathName and FileName and have the FileStream object do a read, and return it into a string.
I can get intellisense to recognize Source.ReadSourceFile, but I haven't figured out away to pass the parameters with this call in the Main():
string Test = Source.ReadSourceFile.Read("C:\\MyFile\\", "TestDir.txt");
Here it is:
using System; using System.IO;
namespace Source {
/// <summary> /// Summary description for Class1. /// </summary>
public class ReadSourceFile { public string Read(string PathName, string FileName) { System.IO.FileStream file = new System.IO.FileStream(PathName + FileName, System.IO.FileMode.Open, FileAccess.Read); StreamReader sr = new StreamReader(file); string s = sr.ReadToEnd(); return s; }
} }
public class main { string Test = Source.ReadSourceFile.Read("C:\\MyFile\\", "TestDir.txt"); }
///End code here
Any help would be appreciated!
Barry
Hi Ansil,
Keeping the same context as in my sample code, can you give me an idea how I
could change it to make it work?
Thanks!
Barry
"Ansil MCAD" <An*******@discussions.microsoft.com> wrote in message
news:E1**********************************@microsof t.com... hi barry , you can do it using
static void Main(string[] args)
The parameter of the Main method is a string array that represents the command-line arguments. Usually you check for the existence of the arguments by testing the Length property
if (args.Length == 0) error "Please enter arguments" else access the arguments using args[0],args[1]..and so on
regards Ansil Dimensions Technopark Trivandrum an****@gmail.com
"Barry Young" wrote:
I have the following .cs file: Hope you can read the code
In the Main() I want to pass the PathName and FileName and have the FileStream object do a read, and return it into a string.
I can get intellisense to recognize Source.ReadSourceFile, but I haven't figured out away to pass the parameters with this call in the Main():
string Test = Source.ReadSourceFile.Read("C:\\MyFile\\", "TestDir.txt");
Here it is:
using System; using System.IO;
namespace Source {
/// <summary> /// Summary description for Class1. /// </summary>
public class ReadSourceFile { public string Read(string PathName, string FileName) { System.IO.FileStream file = new System.IO.FileStream(PathName + FileName, System.IO.FileMode.Open, FileAccess.Read); StreamReader sr = new StreamReader(file); string s = sr.ReadToEnd(); return s; }
} }
public class main { string Test = Source.ReadSourceFile.Read("C:\\MyFile\\", "TestDir.txt"); }
///End code here
Any help would be appreciated!
Barry
Hi,
I don't exactly understand what are you trying to do (I guess it's not
passing command-line parameters as Ansil wrote).
If you just can't get your code to compile, see inline:
"Barry Young" <yo******@insightbb.com> wrote in message
news:xPZjd.316064$wV.275593@attbi_s54... Hi Ansil,
Keeping the same context as in my sample code, can you give me an idea how I could change it to make it work?
Thanks!
Barry
"Ansil MCAD" <An*******@discussions.microsoft.com> wrote in message news:E1**********************************@microsof t.com... hi barry , you can do it using
static void Main(string[] args)
The parameter of the Main method is a string array that represents the command-line arguments. Usually you check for the existence of the arguments by testing the Length property
if (args.Length == 0) error "Please enter arguments" else access the arguments using args[0],args[1]..and so on
regards Ansil Dimensions Technopark Trivandrum an****@gmail.com
"Barry Young" wrote:
I have the following .cs file: Hope you can read the code
In the Main() I want to pass the PathName and FileName and have the FileStream object do a read, and return it into a string.
I can get intellisense to recognize Source.ReadSourceFile, but I haven't figured out away to pass the parameters with this call in the Main():
string Test = Source.ReadSourceFile.Read("C:\\MyFile\\", "TestDir.txt");
Here it is:
using System; using System.IO;
namespace Source {
/// <summary> /// Summary description for Class1. /// </summary>
public class ReadSourceFile { public string Read(string PathName, string FileName)
Replace with: public static string Read(string PathName, string FileName)
If the function is not static, you must first instantiate an object to and
call methods on it.
{ System.IO.FileStream file = new System.IO.FileStream(PathName + FileName, System.IO.FileMode.Open, FileAccess.Read); StreamReader sr = new StreamReader(file); string s = sr.ReadToEnd(); return s; }
} }
public class main {
Where's the Main() method?
static void Main()
{ string Test = Source.ReadSourceFile.Read("C:\\MyFile\\", "TestDir.txt");
}
}
I hope the rest should work OK Here is a complete code that works for me:
using System;
using System.IO;
namespace Source
{
/// <summary>
/// Summary description for Class1.
/// </summary>
public class ReadSourceFile
{
public static string Read(string pathName, string fileName)
{
using (StreamReader sr = new StreamReader(Path.Combine(pathName,
fileName)))
return sr.ReadToEnd();
}
}
}
public class main
{
static void Main()
{
string test = Source.ReadSourceFile.Read("C:\\MyFile\\",
"TestDir.txt");
}
}
Please note that it's always recommended to dispose objects that implement
the IDisposable interface. Also it's not required to create a FileStream and
then a StreamReader from it.
HTH,
Stefan
///End code here
Any help would be appreciated!
Barry
hi
i got your problem now
the parameters you pass contains slashes
so use it like this
Source.ReadSourceFile.Read(@"C:\\MyFile\\", "TestDir.txt");
and make your Read method of the calss ReadSourceFile as static
public static string Read(string PathName, string FileName)
Ansil
Dimensions
Technopark
Trivandrum an****@gmail.com
"Barry Young" wrote: Hi Ansil,
Keeping the same context as in my sample code, can you give me an idea how I could change it to make it work?
Thanks!
Barry
"Ansil MCAD" <An*******@discussions.microsoft.com> wrote in message news:E1**********************************@microsof t.com... hi barry , you can do it using
static void Main(string[] args)
The parameter of the Main method is a string array that represents the command-line arguments. Usually you check for the existence of the arguments by testing the Length property
if (args.Length == 0) error "Please enter arguments" else access the arguments using args[0],args[1]..and so on
regards Ansil Dimensions Technopark Trivandrum an****@gmail.com
"Barry Young" wrote:
I have the following .cs file: Hope you can read the code
In the Main() I want to pass the PathName and FileName and have the FileStream object do a read, and return it into a string.
I can get intellisense to recognize Source.ReadSourceFile, but I haven't figured out away to pass the parameters with this call in the Main():
string Test = Source.ReadSourceFile.Read("C:\\MyFile\\", "TestDir.txt");
Here it is:
using System; using System.IO;
namespace Source {
/// <summary> /// Summary description for Class1. /// </summary>
public class ReadSourceFile { public string Read(string PathName, string FileName) { System.IO.FileStream file = new System.IO.FileStream(PathName + FileName, System.IO.FileMode.Open, FileAccess.Read); StreamReader sr = new StreamReader(file); string s = sr.ReadToEnd(); return s; }
} }
public class main { string Test = Source.ReadSourceFile.Read("C:\\MyFile\\", "TestDir.txt"); }
///End code here
Any help would be appreciated!
Barry
You can either alter your main to create a "ReadSourceFile" object, then
call "Read' on it, or make "Read" static. The way you have it, you're
trying to call a method on a type, but the method can only be called on an
instance of that type
so for #1 change main (to call the method on an instance):
public class main
{
ReadSourceFile r = new Source.ReadSourceFile();
string Test = r.Read("C:\\MyFile\\", "TestDir.txt");
}
....
or for #2 (to make the method defined on the type, not on instance) change
ReadSourceFile to
public class ReadSourceFile
{
public static string Read(string PathName, string FileName)
{
System.IO.FileStream file = new System.IO.FileStream(PathName + FileName,
System.IO.FileMode.Open, FileAccess.Read);
StreamReader sr = new StreamReader(file);
string s = sr.ReadToEnd();
return s;
}
--
-Philip Rieck http://philiprieck.com/blog/
-
"Barry Young" <yo******@insightbb.com> wrote in message
news:TNWjd.74110$R05.48439@attbi_s53... I have the following .cs file: Hope you can read the code
In the Main() I want to pass the PathName and FileName and have the FileStream object do a read, and return it into a string.
I can get intellisense to recognize Source.ReadSourceFile, but I haven't figured out away to pass the parameters with this call in the Main():
string Test = Source.ReadSourceFile.Read("C:\\MyFile\\", "TestDir.txt");
Here it is:
using System; using System.IO;
namespace Source {
/// <summary> /// Summary description for Class1. /// </summary>
public class ReadSourceFile { public string Read(string PathName, string FileName) { System.IO.FileStream file = new System.IO.FileStream(PathName + FileName, System.IO.FileMode.Open, FileAccess.Read); StreamReader sr = new StreamReader(file); string s = sr.ReadToEnd(); return s; }
} }
public class main { string Test = Source.ReadSourceFile.Read("C:\\MyFile\\", "TestDir.txt"); }
///End code here
Any help would be appreciated!
Barry
You can either alter your main to create a "ReadSourceFile" object, then
call "Read' on it, or make "Read" static. The way you have it, you're
trying to call a method on a type, but the method can only be called on an
instance of that type
so for #1 change main (to call the method on an instance):
public class main
{
ReadSourceFile r = new Source.ReadSourceFile();
string Test = r.Read("C:\\MyFile\\", "TestDir.txt");
}
....
or for #2 (to make the method defined on the type, not on instance) change
ReadSourceFile to
public class ReadSourceFile
{
public static string Read(string PathName, string FileName)
{
System.IO.FileStream file = new System.IO.FileStream(PathName + FileName,
System.IO.FileMode.Open, FileAccess.Read);
StreamReader sr = new StreamReader(file);
string s = sr.ReadToEnd();
return s;
}
--
-Philip Rieck http://philiprieck.com/blog/
-
"Barry Young" <yo******@insightbb.com> wrote in message
news:TNWjd.74110$R05.48439@attbi_s53... I have the following .cs file: Hope you can read the code
In the Main() I want to pass the PathName and FileName and have the FileStream object do a read, and return it into a string.
I can get intellisense to recognize Source.ReadSourceFile, but I haven't figured out away to pass the parameters with this call in the Main():
string Test = Source.ReadSourceFile.Read("C:\\MyFile\\", "TestDir.txt");
Here it is:
using System; using System.IO;
namespace Source {
/// <summary> /// Summary description for Class1. /// </summary>
public class ReadSourceFile { public string Read(string PathName, string FileName) { System.IO.FileStream file = new System.IO.FileStream(PathName + FileName, System.IO.FileMode.Open, FileAccess.Read); StreamReader sr = new StreamReader(file); string s = sr.ReadToEnd(); return s; }
} }
public class main { string Test = Source.ReadSourceFile.Read("C:\\MyFile\\", "TestDir.txt"); }
///End code here
Any help would be appreciated!
Barry This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: pauldepstein |
last post by:
I am reading Grimshaw and Ortega's "C++ and Numerical Methods." They
construct a vector class which contains the variable vec, a float*
variable where the length of the array (number of...
|
by: DH |
last post by:
I have a VERY basic question about figuring database size. I've inherited a
database which is generally similar to this basic one:
Item, Red, Blue, Green, Yellow
(text), (int),(int),(int),(int)...
|
by: Malcolm |
last post by:
After some days' hard work I am now the proud possessor of an ANSI C BASIC
interpreter.
The question is, how is it most useful?
At the moment I have a function
int basic(const char *script,...
|
by: Ramesh |
last post by:
hi,
Let me ask some basic questions.
Can anybody explain me about the following questions:
1. When we have to create sn key? Whenever we compiled
Component we have to create or it is a one time...
|
by: Pete |
last post by:
I'm cross posting from mscom.webservices.general as I have received no answer
there:
There has been a number of recent posts requesting how to satisfactorily
enable BASIC authorization at the...
|
by: Aussie Rules |
last post by:
Hi,
Having a mental block on this one. Have done it before but can't rack my
brain on how...
I have an object, with a bunch on property, and I add that object to a combo
box. I want the...
|
by: MikeB |
last post by:
I've been all over the net with this question, I hope I've finally
found a group where I can ask about Visual Basic 2005.
I'm at uni and we're working with Visual Basic 2005. I have some books,
...
|
by: frankhanretty |
last post by:
Do I have to install Visual basic on the remote terminals as I did on the server?
I have an visual basic 5 application running fine on my client's server and he is now networked. He wants to run the...
|
by: Chris Asaipillai |
last post by:
Hi there
My compay has a number of Visual Basic 6 applications which are front endeed onto
either SQL Server or Microsoft Access databases.
Now we are in process of planning to re-write these...
|
by: Scott Stark |
last post by:
Hello,
I'm trying to get a better handle on OOP programming principles in VB.NET.
Forgive me if this question is sort of basic, but here's what I want to do.
I have a collection of Employee...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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: 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,...
|
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...
|
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...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
| |