private void btnUpload_Click(object sender, EventArgs e)
 {
     //if (Enum.GetNames(typeof(DefinedFileTypes)).Equals(Path.GetExtension(fileToUpload).ToUpper().Replace(@".", "")))
     if (Enum.IsDefined(typeof(DefinedFileTypes), Path.GetExtension(fileToUpload).ToUpper().Replace(@".", "")))
     {
         try
         {
             int id = AddFile(txtFileName.Text, txtDesc.Text);
             if (id != 0)
             {
                 using (Stream fileStream = new FileStream(fullFilePath, FileMode.Open, FileAccess.Read))
                 {
                     var request = new FileUploadMessage();
                     var fileMetaData = new ClientApp.FileUploadService.FileMetaData();
                     string ft = fileToUpload.Substring(fileToUpload.LastIndexOf('.') + 1);
                     fileMetaData.FileName = id.ToString() + "." + ft;
                     fileMetaData.FullLocalPath = fullFilePath;
                     fileMetaData.FileType = (DefinedFileTypes)Enum.Parse(typeof(DefinedFileTypes), Path.GetExtension(fileToUpload).ToUpper().Replace(@".", ""));
                     request.Metadata = fileMetaData;
                     request.FileByteStream = fileStream;
                     FileUploadMessage fum = new FileUploadMessage(fileMetaData, fileStream);
                     client.UploadFile(fum);
                 }
                 client.Close();
             }
         }
         catch (IOException ioException)
         {
             // throw new FileTransferProxyException("Unable to open the file to upload");
             MessageBox.Show("File error!" + ioException);
         }
         catch (Exception ex)
         {
             //throw new FileTransferProxyException(e.Message);
             MessageBox.Show("Error in upload, please try again. If this continue contact administrator :(" + ex);
         }
         finally
         {
             lblError.ForeColor = System.Drawing.Color.Green;
             lblError.Text = "File uploaded";
         }
     }
     else
         MessageBox.Show("Come on man, you need to select a file ;) \n or this is a bad filetype we don't allow");
 }
        private void btnUpload_Click(object sender, EventArgs e)
        {
            bool typeCheck = true;
            for (int q = 0; q < dataGridView1.Rows.Count && typeCheck; q++)
            {
                if (!Enum.IsDefined(typeof(DefinedFileTypes), Path.GetExtension(dataGridView1.Rows[q].Cells[0].Value.ToString()).ToUpper().Replace(@".", "")))
                {
                    typeCheck = false;
                }
            }
            int i = 0;
            bool stop = false;
            if (fullFilePathList != null && fileToUploadList != null)
            {
                if (typeCheck)
                {
                    try
                    {
                        List<int> ids = AddFiles();
                        foreach (int q in ids)
                        {
                            if (q == 0)
                            {
                                stop = true;
                            }
                        }
                        if (!stop)
                        {
                            foreach (string fullFilePath in fullFilePathList)
                            {
                                using (Stream fileStream = new FileStream(fullFilePath, FileMode.Open, FileAccess.Read))
                                {
                                    var request = new FileUploadMessage();
                                    var fileMetaData = new ClientApp.FileUploadService.FileMetaData();

                                    string ft = fileToUploadList[i].Substring(fileToUploadList[i].LastIndexOf('.') + 1);
                                    fileMetaData.FileName = ids[i] + "." + ft;
                                    fileMetaData.FullLocalPath = fullFilePath;
                                    fileMetaData.FileType = (ClientApp.FileUploadService.DefinedFileTypes)Enum.Parse(typeof(ClientApp.FileUploadService.DefinedFileTypes), Path.GetExtension(fileToUploadList[i]).ToUpper().Replace(@".", ""));
                                    request.Metadata = fileMetaData;
                                    request.FileByteStream = fileStream;
                                    FileUploadMessage fum = new FileUploadMessage(fileMetaData, fileStream);
                                    client.UploadFile(fum);
                                }
                                i++;
                            }

                            client.Close();
                        }

                    }
                    catch (IOException ioException)
                    {
                        // throw new FileTransferProxyException("Unable to open the file to upload");
                        MessageBox.Show("File error!" + ioException);
                    }
                    catch (Exception ex)
                    {
                        //throw new FileTransferProxyException(e.Message);
                        MessageBox.Show("Error in upload, please try again. If this continue contact administrator :(" + ex);
                    }
                    finally
                    {
                        lblError.Text = "File uploaded";
                    }

                }
                else
                {
                    MessageBox.Show("Bad filetype(s)");
                }
            }
            else
            {
                MessageBox.Show("no files seleced");
            }
        }