Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to upload a file in window forms? [closed]

Tags:

winforms

In window forms, how to upload a file, I did not found any file upload control. Can you give me any reference? I want to store the document with in my systems drive. Thank you.

like image 953
Ssasidhar Avatar asked Oct 19 '12 05:10

Ssasidhar


People also ask

How do I enable file upload in Microsoft forms?

In Microsoft Forms, open the form you want to edit. Add new. Select More question types , and then select File upload. Note: File upload is only available when “Only people in my organization can respond” or “Specific people in my organization can respond” is the selected setting.

Why is file upload disabled in MS forms?

File Upload option is greyed out in the following conditions: Form is set to Anyone with the link can respond option. You are editing the form as collaborator.


1 Answers

You can put on your form button and create click handler to it with the following code:

private void buttonGetFile_Click(object sender, EventArgs e)
{
    OpenFileDialog dialog = new OpenFileDialog();
    dialog.Filter = "Text files | *.txt"; // file types, that will be allowed to upload
    dialog.Multiselect = false; // allow/deny user to upload more than one file at a time
    if (dialog.ShowDialog() == DialogResult.OK) // if user clicked OK
    {
        String path = dialog.FileName; // get name of file
        using (StreamReader reader = new StreamReader(new FileStream(path, FileMode.Open), new UTF8Encoding())) // do anything you want, e.g. read it
        {
                // ...
        }
    }
}
like image 54
Eadel Avatar answered Oct 16 '22 01:10

Eadel