C# WINFORM 上传图片 并保存在程序的根目录的某个文件夹中

原文地址:http://www.cnblogs.com/right_forever/archive/2011/05/31/2064257.html


C# WINFORM 上传图片 并保存在程序的根目录的某个文件夹中在页面不打开图片

        private void btnUpLoad_Click(object sender, EventArgs e)
        {
            DialogResult dr = openFileDialog1.ShowDialog();
            if (dr == DialogResult.OK)
            {
                image = openFileDialog1.FileName;
                picpath = openFileDialog1.FileName;
                t = 1;
                pictureBox1.Image = Image.FromFile(image);

                File.Copy(openFileDialog1.FileName, Application.StartupPath + "\\Image\\" + id + ".jpg");
            }
        }


C# WINFORM 上传图片 并保存在程序的根目录的某个文件夹中  在页面  打开图片

private void btnBrowse_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialogTemp = new OpenFileDialog();
            DialogResult dr = openFileDialogTemp.ShowDialog();
            if (dr == DialogResult.OK)
            {
                string image = openFileDialogTemp.FileName;
                string picpath = openFileDialogTemp.FileName;

                pictureBox1.Image = Image.FromFile(image);
                this.txtPath.Text = image;
            }
        }

        private void btnUpload_Click(object sender, EventArgs e)
        {
            if (!Directory.Exists(AppDomain.CurrentDomain.BaseDirectory + @"Temp\"))
            {
                Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + @"Temp\");
            }
            string tempFileName = AppDomain.CurrentDomain.BaseDirectory + @"Temp\" + Guid.NewGuid().ToString() + ".jpg";
            File.Copy(this.txtPath.Text, tempFileName);
            FileHelper.UploadFile(tempFileName);
            File.Delete(tempFileName);

        }


你可能感兴趣的:(C#,WinForm,图片上传)