winform中如何将本地图片上传到服务器
2013-05-13 14:39
288 查看
pictureBox1.BackgroundImage = null;
OpenFileDialog ofDlg = new OpenFileDialog();
DialogResult dRet = ofDlg.ShowDialog();
if (dRet == DialogResult.OK)
{
string strFile = ofDlg.FileName;
string type = strFile.Substring(strFile.LastIndexOf(".") + 1);
if (type == "bmp" || type == "jpg" || type == "gif" || type == "jpeg" || type == "png")
{
txtSingle.Text = strFile;
pictureBox1.ImageLocation = txtSingle.Text;
System.IO.Directory.SetCurrentDirectory(Application.StartupPath);
lblShow.Hide();
}
else
{
MessageBox.Show("不是有效的图片格式!");
}
}
else
{
txtSingle.Text = "";
}
上传代码:
string filepath = this.txtSingle.Text.Trim();
if (filepath == string.Empty)
{
MessageBox.Show("图片路径不能为空!");
return;
}
FileInfo info = new FileInfo(filepath);
string imgpath = "\\images\\";
//string dirpath = Application.StartupPath + imgpath;
string dirpath = \\\\ip\\路径\\+ imgpath
try
{
if (!Directory.Exists(dirpath))
{
Directory.CreateDirectory(dirpath);
}
info.CopyTo(dirpath + info.Name, true);
txtSingle.Text = imgpath + info.Name;
MessageBox.Show("图片上传成功!");
}
catch (Exception ex)
{
lblShow.Show();
this.lblShow.Text = "图片上传失败,失败原因:" + ex.Message;
}
OpenFileDialog ofDlg = new OpenFileDialog();
DialogResult dRet = ofDlg.ShowDialog();
if (dRet == DialogResult.OK)
{
string strFile = ofDlg.FileName;
string type = strFile.Substring(strFile.LastIndexOf(".") + 1);
if (type == "bmp" || type == "jpg" || type == "gif" || type == "jpeg" || type == "png")
{
txtSingle.Text = strFile;
pictureBox1.ImageLocation = txtSingle.Text;
System.IO.Directory.SetCurrentDirectory(Application.StartupPath);
lblShow.Hide();
}
else
{
MessageBox.Show("不是有效的图片格式!");
}
}
else
{
txtSingle.Text = "";
}
上传代码:
string filepath = this.txtSingle.Text.Trim();
if (filepath == string.Empty)
{
MessageBox.Show("图片路径不能为空!");
return;
}
FileInfo info = new FileInfo(filepath);
string imgpath = "\\images\\";
//string dirpath = Application.StartupPath + imgpath;
string dirpath = \\\\ip\\路径\\+ imgpath
try
{
if (!Directory.Exists(dirpath))
{
Directory.CreateDirectory(dirpath);
}
info.CopyTo(dirpath + info.Name, true);
txtSingle.Text = imgpath + info.Name;
MessageBox.Show("图片上传成功!");
}
catch (Exception ex)
{
lblShow.Show();
this.lblShow.Text = "图片上传失败,失败原因:" + ex.Message;
}
相关文章推荐
- Winform如何通过TextBox上传图片到服务器
- winform如何上传图片到服务器
- 关于KindEditor组件上传本地图片报服务器异常的错误
- 如何用服务器的image控件实现图片上传御览
- EXTJS图片上传预览(含本地上传前预览和服务器图片预览)
- 如何使用http或httpClient向服务器上传图片 以及使用http上传图片时协议的描述
- java从服务器上传本地图片到图片服务器
- HTML5 本地裁剪图片并上传至服务器
- C# Winform 上传本地文件到服务器路径
- 根据本地相片路径上传图片到服务器的2中方法
- Java本地web项目页面如何直接访问另一台服务器的图片文件
- thinkphp微信开发之jssdk图片上传并下载到本地服务器
- IE7 预览待上传的本地图片(Image Upload Preview) ,放上服务器浏览就不行了。什么破IE7,这个都不支持了
- html的img中使用SVG图片做SRC在本地测试可用但是上传服务器后不能显示问题解决
- 图片上传处理——上传本地服务器
- HTML5 本地裁剪图片并上传至服务器(老梗)
- HTML5 本地裁剪图片并上传至服务器(老梗)
- JAVA web 上传图片至服务器(本地Linux服务器与Fastdfs)
- jsp中如何上传图片到服务器
- express(jade或ejs)如何实现上传图片到服务器并在客户端展示(在客户端可以删除)