Click here to Skip to main content
15,897,891 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everyone,

I am creating a window project in asp.net c#. In which my requirement is that user can browse an image and upload that image. So I want that after browse that image/video path of file should be save in database and file should be save in folder in my project.

please give me code to do this. i have no idea about coding in window project.
I have tried a lot on internet but i could not find the solution.

Please help me...

Thanks in advance
Posted

You will be needing OpenFileDialog to let the user browse the file.

Find the usage here: http://msdn.microsoft.com/en-us/library/system.windows.forms.openfiledialog.aspx[^]

And to save this file you will perhaps be needing the static functions of File class like File.Copy to save them to your directory.

In between you can extract out the file names and push them in the DB for record keeping.
 
Share this answer
 
Comments
coolnavjot31 14-May-12 5:39am    
Hi Rahul ,

thanks a lot. It is worked.

Thanku
VJ Reddy 15-May-12 4:36am    
Good answer. 5!
I hope this helps
C#
using (OpenFileDialog dlg = new OpenFileDialog())
                {

                    dlg.Filter = "JPG Files (*.jpg)|*.jpg|JPEG Files (*.jpeg)|*.jpeg|bmp Files (*.bmp)|*.bmp|PNG Files (*.png)|*.png|GIF Files (*.gif)|*.gif";
                    if (dlg.ShowDialog() == DialogResult.OK)
                    {
                        FileInfo file = new FileInfo(dlg.FileName);

                        if (file.Length == 0)
                        {
                            MessageBox.Show("Invalid image. Please select valid image.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                            return;
                        }
                        else if (file.Length > 2097152)
                        {
                            MessageBox.Show("Image size cannot exceed 2MB.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                            return;
                        }
                        //SAVE YOUR FILE HERE. IN  THIS CASE IT WILL BE IMAGE

                    }

                }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900