Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8550993
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:05:38+00:00 2026-06-11T14:05:38+00:00

I’m trying to write a software that transfers a file from the server to

  • 0

I’m trying to write a software that transfers a file from the server to a client… This is how my software works.. On the client-side it gets an IP and a port then spawns a new object from the Client class to a new Thread and passes the ip and the port to the constructor and the client handles the connection and transfers the file to a byte[] variable.. Now I want to prompt the user with a saveFileDialog to save the file…But I don’t have access to the parent class which is my Form. so I can’t do something like savefiledialog.ShowDialog()… What is the solution to this problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T14:05:39+00:00Added an answer on June 11, 2026 at 2:05 pm

    An event as @syned suggested is a good solution. It is kind of an observer, but in this example you need to interact with the observable class (the client).

    You can declare an event in your client class, so when a file is to be received this event can be used. A normal approach is to have a special “context class” which you fill with the values you need.

    public class Client {
        public event EventHandler<ReceivedFileEventArgs> ReceivedFile;
    
        private ReceivedFileEventArgs onReceivedFile() {
            EventHandler<ReceivedFileEventArgs> handler = ReceivedFile;
            ReceivedFileEventArgs args = new ReceivedFileEventArgs();
            if (handler != null) { handler(this, args); }
            return args;
        }
    
        private void receiveFileCode() {
            // this is where you download the file
            ReceivedFileEventArgs args = onReceivedFile();
            if (args.Cancel) { return; }
            string filename = args.FileName;
            // write to filename
        }
    }
    
    public class ReceivedFileEventArgs {
        public string FileName { get; set; }
        public bool Cancel { get; set; }
    }
    

    Now, in your GUI class you can “listen” to this event, and set the filename to what you want.

    public class MyForm : Form {
       public MyForm() { Initialize(); }
    
       protected void buttonClick(object sender, EventArgs e) {
           // Suppose we initialize a client on a click of a button
           Client client = new Client();
           // note: don't use () on the function here
           client.ReceivedFile += onReceivedFile;
           client.Connect();
       }
    
       private void onReceivedFile(object sender, ReceivedFileEventArgs args) {
           if (InvokeRequired) {
               // we need to make sure we are on the GUI thread
               Invoke(new Action<object, args>(onReceivedFile), sender, args);
               return;
           }
           // we are in the GUI thread, so we can show the SaveFileDialog
           using (SaveFileDialog dialog = new SaveFileDialog()) {
               args.FileName = dialog.FileName;
           }
       }
    }
    

    So, what is an event? In simple terms it’s a function pointer (but please read up on it for more details). So, you tell your client class to call the function when something happens, when a file is to be received for instance. You use events pretty much all the time when using Windows Forms, such as when you assign a button click to a function in your code behind file.

    Now, using this pattern, you can have more events, such as a FileDownloadCompleted for instance.

    Also note the += syntax. You don’t assign an event to a function, you tell the event to call the function when something happens. You can even have two functions on the same event if you want.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I know there's a lot of other questions out there that deal with this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to create an if statement in PHP that prevents a single post
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am trying to understand how to use SyndicationItem to display feed which is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.