473,396 Members | 1,929 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,396 software developers and data experts.

passing parameters

Hi i need to write a C# application that runs daily and takes 2 parameters. How to do this?Ho wto write a c# program that accepts parameters at runtime. I need to supply parametrs in command prompt. Can anybody help me?
Jan 2 '07 #1
6 1543
bplacker
121 100+
a little more clarification would be nice.

but yes, it is possible to pass parameters to a function at the command prompt as far as I know.
Jan 2 '07 #2
Hi,

I need to run the program in command prompt with two parameters.
Create the .exe for my application(say order.exe) and run it in command prompt as..

order parameter 1 parameter 2.

How to read these passed parameters in the program?
Jan 3 '07 #3
bplacker
121 100+
well as soon as the user hit enter, you could say console.readline(), and get the two parameters and pass them to a function or use them in that 'program', whichever you want.
Jan 3 '07 #4
Finally after much googling..i got it..i used the string args and .exe.config file....Thanks for ur help
Jan 3 '07 #5
string filepath="";
if( args[0].ToUpper() == "TST" && args[1].ToUpper() == "ATS")
filepath=ConfigurationSettings.AppSettings["TST_ATS"];
//////////////////
i have this tag in the config file..
<add key="TST_ATS" value=@"c:\order\ats_attributeld.txt"/>
///////////////////////
I get this exception when i execute the above code with the two parameters TST ATS
'System.ArgumentNullException

filepath is being null...its not getting the path from the config file.

Any help??????????
Jan 3 '07 #6
GRDev
3
This is the code for to read the file in c#

using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;
using System.IO;


namespace getfiles
{
class Program
{
static void Main(string[] args)
{
string filepath = "";
if (args[0].ToUpper() == "TST" && args[1].ToUpper() == "ATS")
filepath = ConfigurationSettings.AppSettings["TST_ATS"];
Console.WriteLine("yours Text File Name:= "+filepath);
StreamReader strRead = new StreamReader(filepath);
string line = strRead.ReadLine();
Console.WriteLine("--------Data in the file------");
Console.WriteLine();
while (line != null)
{
Console.WriteLine(line);
line = strRead.ReadLine();
}
strRead.Close();





Console.ReadLine();
}
}
}



///this is the app.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="TST_ATS" value="C:\MSDN\read.txt"/>
</appSettings>
</configuration>


//// how to execut
getfiles.exe TST ATS
Jan 6 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: zlatko | last post by:
There is a form in an Access Project (.adp, Access front end with SQL Server) for entering data into a table for temporary storing. Then, by clicking a botton, several action stored procedures...
7
by: Pavils Jurjans | last post by:
Hallo, I have been programming for restricted environments where Internet Explorer is a standard, so I haven't stumbled upon this problem until now, when I need to write a DOM-compatible code. ...
3
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) {...
12
by: Joel | last post by:
Hi all, Forgive me if I've expressed the subject line ill. What I'm trying to do is to call a c++ function given the following: a. A function name. This would be used to fetch a list of...
7
by: Harolds | last post by:
The code below worked in VS 2003 & dotnet framework 1.1 but now in VS 2005 the pmID is evaluated to "" instead of what the value is set to: .... xmlItems.Document = pmXML // Add the pmID...
39
by: Mike MacSween | last post by:
Just spent a happy 10 mins trying to understand a function I wrote sometime ago. Then remembered that arguments are passed by reference, by default. Does the fact that this slowed me down...
17
by: Charles Sullivan | last post by:
The library function 'qsort' is declared thus: void qsort(void *base, size_t nmemb, size_t size, int(*compar)(const void *, const void *)); If in my code I write: int cmp_fcn(...); int...
4
by: Mike Dinnis | last post by:
Hi, I've been working through a number of turorials to try to learn more about retrieving data from a SQL database. I think i've mastered techniques where i create a sql string in the page and...
2
by: csmith8933 | last post by:
How do I write a function where the number of parameters it takes varies? This is what I have but it doesnt work. // function prototype void functionThree(int num1=1, int num2=2, int num3=3);...
3
by: ajaymohank | last post by:
hello everyone..... i am ajay and i am new to php. in my project i have an option to invoke a bat file by passing parrameters and to diplay the result. i tried this code but my page got hung or...
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?
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...
0
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,...
0
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...
0
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...
0
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...
0
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...
0
agi2029
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 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.