0

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

Edited by __avd: Added [code] tags.

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by CJdamaster
0

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;

Edited by CJdamaster: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.