No it’s not that kind of basic question. I am doing a application and got a scenerio like, the file will be downloaded then it will be uploaded to the FTP server, then the local copy will be deleted, then one entry will be placed in a dictionary for that filename. So, the code is below
public void download_This_WebPage(string url, string cookies_String, string local_Saving_File_Name_With_Path)
{
WebClient wb = new WebClient();
wb.Headers.Add(HttpRequestHeader.Cookie, cookies_String);
// Below I want to pass this local_File _Path to the event handler
wb.DownloadFileCompleted += new System.ComponentModel.AsyncCompletedEventHandler(wb,);
wb.DownloadFileAsync(new Uri(url), local_Saving_File_Name_With_Path + ".html");
}
public void data_Download_Completed(Object sender, System.ComponentModel.AsyncCompletedEventArgs args)
{
//use the file name to upload the file to FTP
}
public FTP_Completed
{
// Delete the file
}
But, I dont know how to pass that filename to the event handler of download_Completed. Can anybody guide me in this
EDIT:
Thank you for the answers from “Darin” and “Frederic”. Is there any general way to pass the custom data to the (already defined)event handler like below
void main_Fn()
{
string my_Data = "Data";
some_object a = new some_object();
some_Object.click_event += new eventHandler(click_Happened);
(Assume that the event passes two ints, I also want to pass the string "my_Data"
to "click_Happened")
some_object.start();
}
void click_Happened(int a, int b)
{
// I want to get the string "my_Data" here.
}
In short how to trick the signature?
You can pass the file name in the
userTokenargument to DownloadFileAsync(). When the operation finishes, it will be available in theUserStateproperty of the AsyncCompletedEventArgs argument passed todata_Download_Completed():Then: