首先设置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就可以上传了。
设置窗体的AllowDrop=True DragEnter事件设置拖动文件时鼠标样式 DragDrop事件中接收拖动的文件,数据库中设置文件类型为image,将文件以2进制的形式保存到数据库中!
只给你一个思路 拖拽记住名字 根据名字上传