程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> .NET實例教程 >> //C#上傳圖片的代碼

//C#上傳圖片的代碼

編輯:.NET實例教程
private void btnPhoto_Click(object sender, EventArgs e)
        {
            string temp;

            string housr = DateTime.Now.Hour.ToString();
            string min = DateTime.Now.Minute.ToString();
            string second = DateTime.Now.Second.ToString();

            temp = housr + min + second ;

            opfdPhoto.InitialDirectory = Application.StartupPath;
            opfdPhoto.FileName = "";

            this.opfdPhoto.Title = "選擇相片";
            opfdPhoto.Filter = "圖片文件(*.jpg;*.bmp;*.gif)|*.jpg;*.bmp;*.gif|所有文件(*.*)|*.*";

            if (opfdPhoto.ShowDialog() == DialogResult.OK)
            {
              
                this.lblPhoto.Text =opfdPhoto.FileName;
                this.ptrPhoto.Image = Image.FromFile(this.opfdPhoto.FileName);
            }
            string fileName

$False$

;
            int pos = this.opfdPhoto.FileName.LastIndexOf("\\");
          
            fileName = this.lblPhoto.Text.Substring(pos + 1, this.lblPhoto.Text.Length - pos - 1);
            //fileName = this.opfdPhoto.FileName.Substring(pos + 1, this.opfdPhoto.FileName.Length - pos - 1);
            //MessageBox.Show(fileName);

             //int ps = this.opfdPhoto.FileName.LastIndexOf(".");

            FileInfo fi = new FileInfo(this.lblPhoto.Text);
            fi.CopyTo(Application.StartupPath + @"\StudentPhoto\" + fileName, true);
            Environment.CurrentDirectory = Application.StartupPath;

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved