VS(C#)应用程序怎么实现文件浏览上传

只要点了“浏览”就能浏览到目标文件,用什么控件,代码怎么写?

工具箱-HTML里面有个file的input控件就可以了,不过这个只能传递几兆的文件,太大的文件就要用专门开发的大文件上传组件了。追问

这是Windows应用程序,没有HTML

追答

搞错了,应用中没有直接的控件,一般是用一个按钮弹出文件操作窗口,给你一个例子函数。
private void butSendFile_Click(object sender, System.EventArgs e)
{
System.Windows.Forms.OpenFileDialog fd = new OpenFileDialog();
fd.Filter = "所有文件|*.*";
if (fd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
System.IO.FileInfo fInfo = new System.IO.FileInfo(fd.FileName);
if (fInfo.Length / (1024 * 1024 * 10) > 0)
{
MessageBox.Show("您传送的文件太大,请联系对方及时接收。", "提示", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information);
sendFileRequest(fd.FileName);
}
else
{
LanMsg.MyPicture pic = new MyPicture();
pic.FileName = fd.FileName.ToString();
System.Random R = new Random();
pic.Tag = R.Next(2000, 20000);
pic.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
pic.Image = System.Drawing.Image.FromFile(GlobalSetting.CurrDir + "\\Resources\\file.gif");
this.RTBSend.InsertMyControl(pic);
this.RTBSend.InsertLink(fInfo.Name + "\n");
this.SendGifs.add(pic);
}
}
}

温馨提示:内容为网友见解,仅供参考
第1个回答  2011-05-26
浏览用 openfiledialog 上传用 webclient追问

具体一点呢?我不会用openfiledialog

追答

先引用命名控件 system.io 然后你就可以用 openfiledialog类了

openfiledialog ofd = new openfiledialog ();

ofd.showdialog();

相似回答