C# WinForm程序 怎么把图片上传到指定的文件夹中 ???
各位前辈
C# WinForm程序 怎么把图片上传到指定的文件夹中 ???
求指教
[解决办法]
同求~~
[解决办法]
自己研究的一下,下面的代码基本上解决了问题
private void btnUpLoad_Click(object sender, EventArgs e)//上传图片
{
DialogResult dr = openFileDialog.ShowDialog();
if (dr == DialogResult.OK)
{
string imgName = openFileDialog.SafeFileName;
string imgpath = openFileDialog.FileName;
picImage.Image = Image.FromFile(imgpath);
File.Copy(openFileDialog.FileName, Application.StartupPath + "\\imgs\" + imgName);
}
}
[解决办法]
http://www.cnblogs.com/Leo_wl/archive/2011/07/15/2107724.html
[解决办法]
这个叫复制
[解决办法]
学习学习
[解决办法]
if (Directory.Exists(filePath))
Directory.CreateDirectory(filePath);
/*上传文件*/
string profilepath = filePath + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls";
byte[] xlsfile = null;
xlsfile = new byte[fileLen];
Stream sm = FileUpload1.PostedFile.InputStream;
sm.Read(xlsfile, 0, fileLen);
sm.Close();
sm.Dispose();
CreateOrUpDateFile(profilepath, xlsfile);
/// <summary>
/// 创建文件
/// </summary>
/// <param name="filePath">创建文件的路径</param>
/// <param name="fileByte">文件(字节)</param>
public void CreateOrUpDateFile(string filePath, byte[] fileByte)
{
filePath = filePath.Replace("/", "\");
Directory.CreateDirectory(filePath.Substring(0, filePath.LastIndexOf("\")));
FileStream sm = new FileStream(filePath, FileMode.Create, FileAccess.Write);
sm.Write(fileByte, 0, fileByte.Length);
sm.Dispose();
sm.Close();
}