5

In my C# Windows application I want to upload a pdf file but in my toolbox I cannot find a FileUpload control.

How can I go about and uploading a pdf file in a C# windows application.?

regards

2
  • Do you mean choose the file or parse it? Commented Nov 14, 2012 at 11:33
  • How to add controls to Visual Studio ToolBox --> Link Commented Nov 14, 2012 at 11:52

3 Answers 3

12

After you put a OpenFileDialog control on your form, let's say that you click a button and:

    private void button1_Click(object sender, EventArgs e)
        {
            DialogResult result = openFileDialog1.ShowDialog();
            if (result == DialogResult.OK) // Test result.
            {
            //Do whatever you want
            //openFileDialog1.FileName .....
            }
        }

it goes something like this :-)

Sign up to request clarification or add additional context in comments.

Comments

1

You can use OpenFileDialog to get the filename of the file you need and then .NET File object to read data from the file. You might need a control being able to display a PDF file. Please read the following:

Viewing PDF in Windows forms using C#

Comments

0
public string GetFile(OpenFileDialog pOFD)
{
    pOFD.Filter = "Excel Files|*.xls;*.xlsx;*.xlsm";
    if (pOFD.ShowDialog() == DialogResult.OK)
    {
        return pOFD.FileName;
    }
    return "";
}

1 Comment

Remember that Stack Overflow isn't just intended to solve the immediate problem, but also to help future readers find solutions to similar problems, which requires understanding the underlying code. This is especially important for members of our community who are beginners, and not familiar with the syntax. Given that, can you edit your answer to include an explanation of what you're doing and why you believe it is the best approach?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.