在C#的C⼀S结构中,怎么实现拖拽多个文件,实现把本地文件上传到数据库中,有控件么?求高手指点下。

如果能够实现的话,还可以获得更多的财富值。
2025-02-24 01:41:51
推荐回答(3个)
回答1:

首先设置Form的AllowDrop=true

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void btnStart_Click(object sender, EventArgs e)
    {
    }

    private void Form1_DragEnter(object sender, DragEventArgs e)
    {
        if (e.Data.GetDataPresent(DataFormats.FileDrop))
        {
            e.Effect = DragDropEffects.Link ;
        }
        else
        {
            e.Effect = DragDropEffects.None;
        }
    }

    private void Form1_DragDrop(object sender, DragEventArgs e)
    {
        string path = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString();
        // 接下来可以通过filestream来上传文件。
    }
}

在DragDrop事件中能够得到拖放到窗体上的文件路径,然后使用filestream就可以上传了。

回答2:

设置窗体的AllowDrop=True DragEnter事件设置拖动文件时鼠标样式 DragDrop事件中接收拖动的文件,数据库中设置文件类型为image,将文件以2进制的形式保存到数据库中!

回答3:

只给你一个思路 拖拽记住名字 根据名字上传