string sourcePhotoPath = this.GetUserSelectedPhoto(); if(sourcePhotoPath == null) { return; } string sourceFileName = System.IO.Path.GetFileName(sourcePhotoPath); //把图片保存到文件夹 string userName = this.LoginUserName; string newPath = @"Images"; if(!System.IO.Directory.Exists(newPath)) { System.IO.Directory.CreateDirectory(newPath); } string destFile = userName + DateTime.Now.ToString("yyyyMMddHHMMss") + "_" + sourceFileName; string destImgPath = System.IO.Path.Combine(newPath, destFile); if(!File.Exists(destImgPath)) { var myFile = File.Create(destImgPath); myFile.Close(); } FileInfo f1 = new FileInfo(sourcePhotoPath); f1.CopyTo(destImgPath,true);