hi everyone.. i am using windows application to get data from web service and according to the result an action will be taken

for example if the result is 1 i will download a file and the name of the file will be taken from my database.

all that i need is to pass the name of the file from the form to the button_click Event

my result is:

private void button1_Click(object sender, EventArgs e)
        {


            WebClient webClient = new WebClient();
            webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);
            webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);
            webClient.DownloadFileAsync(new Uri("http://www.myexample.com/john_test/Setup.msi"), @"c:\Setup.msi");

        }

i want it to be

private void button1_Click(object sender, EventArgs e)
        {


            WebClient webClient = new WebClient();
            webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);
            webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);
       webClient.DownloadFileAsync(new Uri("http://www.myexample.com/john_test/"[b]+Result[/b]), @"c:\"[b]+Result[/b]);

        }

i want to pass variable to the button or use something like Global variable but i dont know how to use its syntax?
can anyone help me please

One way of doing it, is just by getting the text inside your OnClick function.

If you had the filename in a text box for example, it could be done like this:

private void button1_Click(object sender, EventArgs e)
        {
            string result = this.textBox1.Text;

            WebClient webClient = new WebClient();
            webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);
            webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);
            webClient.DownloadFileAsync(new Uri("http://www.myexample.com/john_test/" + result), @"c:\" + result);
        }

Otherwise, global variables can be declared both outside and inside functions by specifying:

public string result = this.textBox1.Text;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.