Question

I am new to C#. How can i possible upload a file like pdf and image in a particular folder using C# windows gui? Do i need to add library for it to work in viewing it directly to the gui program? Also, i need to allow the user to upload multiple files. Thanks in advance !

Was it helpful?

Solution

If you want to browse and display picture inside a picture box on your windows form you can try something like this:

Design of the form:

Windows form design

Code:

public PictureDisplay()
{
    InitializeComponent();
}

private void btnBrowse_Click(object sender, EventArgs e)
{
    OpenFileDialog newDialog = new OpenFileDialog();
    if (newDialog.ShowDialog() == DialogResult.OK)
    {
        try
        {
            picBoxDisplay.Load(newDialog.FileName);
            picBoxDisplay.SizeMode = PictureBoxSizeMode.Zoom;
        }
        catch
        {
            MessageBox.Show("Wrong file type!", "Error");
        }
    }
}

Code opens file dialog and if you choose a file of image type it's displayed to fit into a picture box while maintaining resolution ratio. If any other type is chosen MessageBox pops and makes you aware of an error.

Results:

App start App browse App image loaded

Hopefully it covers the image upload to GUI part. For any further help, please explain the question better, thanks!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top