浏览并以窗口形式上载文件夹中的文件 [英] Browse and upload a file in folder in window form

查看:76
本文介绍了浏览并以窗口形式上载文件夹中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在asp.net c#中创建一个窗口项目.我的要求是用户可以浏览图像并上传该图像.因此,我希望浏览后文件的图像/视频路径应保存在数据库中,文件应保存在我项目的文件夹中.

请给我代码以执行此操作.我不知道在window项目中进行编码.
我在互联网上尝试了很多,但找不到解决方案.

请帮帮我...

在此先谢谢您

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

推荐答案

您将需要OpenFileDialog 让用户浏览文件.

在此处查找用法: http://msdn.microsoft.com/zh-CN /library/system.windows.forms.openfiledialog.aspx [ ^ ]

要保存此文件,您可能需要File 类的静态函数(如File.Copy)将其保存到目录中.

在这两者之间,您可以提取文件名并将其推送到数据库中以进行记录保存.
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.


我希望这会有所帮助
I hope this helps
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

                    }

                }


这篇关于浏览并以窗口形式上载文件夹中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆