0

I want to add new employee to web service. The employee photo should be sent as an attachment with the web service. and sent as a password protected ZIP file.

Amir Salah
  • 31
  • 9

1 Answers1

0

Create a class for your image and send as a stream as follows,

You have to add the stream conversion for each image and add the details to a list.

in the client side.

Stream stream = (Stream)openDialog.File.OpenRead();
                    byte[] bytes = new byte[stream.Length];
                    stream.Read(bytes, 0, (int)stream.Length);
                    BitmapImage bmi = new BitmapImage();
                    using (MemoryStream ms = new MemoryStream(bytes))
                    {
                        bmi.SetSource(ms);
                        newRow.Thumbnail = bmi;
                }

in your service side

string filePath = ConfigurationManager.AppSettings.Get("ImageUploadPath");

                          if (!Directory.Exists(filePath))
                          {
                              Directory.CreateDirectory(filePath);
                          }

                          filePath = filePath + "\\" + picture.FileName + "." + picture.FileType;

                          if (picture.FileName != string.Empty)
                          {
                              fileStream = File.Open(filePath, FileMode.Create);
                              writer = new BinaryWriter(fileStream);
                              writer.Write(picture.FileStream);
                          }
Sajeetharan
  • 216,225
  • 63
  • 350
  • 396