图片上传

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace DeleteAllFiles
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            openFileDialog1.Filter="JPEG(*.jpg;*.jpe;*.jpeg)|*.jpg";
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
              
                textBox1.Text = openFileDialog1.FileName;
                FileInfo newFile = new FileInfo(textBox1.Text);  
                string newPath = "";
                if (newFile.Exists)
                { 
                    string[] path = System.Windows.Forms.Application.StartupPath.Split(new char[]{'\\'});//应用程序可执行文件的路径,但不包括可执行文件名称
             
                for (int i = 0; i < path.Length-2; i++)
                {
                    newPath += path[i]+"\\";//取到bin以前的地址
                }
                    //if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                    //{
                newFile.CopyTo(newPath + "Images\\" + newFile.Name, true);//文件保存至新路径下
                    //}
                }
             

                pictureBox1.ImageLocation =newPath+"Images\\"+ newFile.Name;
            }
        }
    }
}

posted on 2012-11-09 15:21  843408615  阅读(85)  评论(0编辑  收藏  举报

导航