示例#1
0
        public void SavePhoto(string userID, Image userPhoto)
        {
            string[] allPhotos = fileRW.CsvFileRead(sourcePath);

            int i;

            //find user
            for (i = 0; i < allPhotos.Length; i += 2)
            {
                if (allPhotos[i] == userID)
                {
                    break;
                }
            }

            string base64;

            using (MemoryStream ms = new MemoryStream())
            {
                userPhoto.Save(ms, ImageFormat.Png);
                byte[] bytes = ms.ToArray();
                base64 = Convert.ToBase64String(bytes);
            }

            if (i < allPhotos.Length)
            {
                allPhotos[i + 1] = base64;
                fileRW.CsvFileWrite(sourcePath, allPhotos);
                return;
            }

            List <string> allPhotoList = new List <string>(allPhotos);

            allPhotoList.Add(userID);
            allPhotoList.Add(base64);
            fileRW.CsvFileWrite(sourcePath, allPhotoList);
            return;
        }