public bool UploadFile(ISiteSetting siteSetting, UploadItem uploadItem, bool saveAsWord, out IItem listItem)
        {
            listItem = null;
            SPFolder spFolder             = uploadItem.Folder as SPFolder;
            string   rootFolderPath       = spFolder.RootFolderPath;
            string   siteURL              = spFolder.SiteUrl;
            string   webURL               = spFolder.WebUrl;
            string   destinationFolderUrl = spFolder.GetUrl(); // spFolder.WebUrl.TrimEnd(new char[] { '/' }) + "/" + spFolder.FolderPath.TrimStart(new char[] { '/' });
            string   listName             = spFolder.ListName;

            byte[] myByteArray     = SharePointServiceManager.ReadByteArrayFromFile(uploadItem.FilePath);
            bool   uploadSucceeded = false;

            string newDestinationUrl            = destinationFolderUrl + "/";
            string copySource                   = uploadItem.FilePath;
            string filename                     = string.Empty;
            KeyValuePair <object, object> title = uploadItem.FieldInformations.Where(f => ((Field)f.Key).Name == "Title").FirstOrDefault();

            if (title.Value != null)
            {
                filename = title.Value.ToString() + new FileInfo(copySource).Extension;
            }
            else
            {
                filename = new FileInfo(copySource).Name;
            }
            string[] copyDest = new string[1] {
                destinationFolderUrl + "/" + filename
            };
            byte[] itemByteArray = SharePointServiceManager.ReadByteArrayFromFile(uploadItem.FilePath);

            SPListItem spListItem;

            string newFileName = copySource;

            #region Conflicts

            /* This should be done before this function is called
             * IOutlookConnector connector = OutlookConnector.GetConnector(uploadItem.Folder.SiteSetting);
             * bool doThisForNextConflicts = false;
             * if ((doThisForNextConflicts == true && lastFileExistDialogResults == FileExistDialogResults.Skip) || lastFileExistDialogResults == FileExistDialogResults.Cancel)
             * {
             *  uploadItem.SharePointListViewControl.DeleteUploadItemInvoke(uploadItem.UniqueID);
             *  return;
             * }
             *
             * bool isCurrentFileUploadCanceled = false;
             * if ((doThisForNextConflicts == false) || (doThisForNextConflicts == true && lastFileExistDialogResults == FileExistDialogResults.Copy))
             * {
             *  while (connector.CheckFileExistency(uploadItem.Folder, null, newFileName) == true)
             *  {
             *      FileExistConfirmationForm fileExistConfirmationForm = new FileExistConfirmationForm(copyDest[0]);
             *      fileExistConfirmationForm.ShowDialog();
             *      lastFileExistDialogResults = fileExistConfirmationForm.FileExistDialogResult;
             *      doThisForNextConflicts = fileExistConfirmationForm.DoThisForNextConflicts;
             *
             *      newFileName = fileExistConfirmationForm.NewFileName;
             *      if (lastFileExistDialogResults == FileExistDialogResults.Skip || lastFileExistDialogResults == FileExistDialogResults.Cancel)
             *      {
             *          uploadItem.SharePointListViewControl.DeleteUploadItemInvoke(uploadItem.UniqueID);
             *          isCurrentFileUploadCanceled = true;
             *          break;
             *      }
             *      if (lastFileExistDialogResults == FileExistDialogResults.CopyAndReplace)
             *      {
             *          break;
             *      }
             *      string newCopyDest = copyDest[0].Substring(0, copyDest[0].LastIndexOf("/")) + "/" + newFileName;
             *      copyDest = new string[] { newCopyDest };
             *  }
             * }
             * if (isCurrentFileUploadCanceled == true)
             *  return;
             */
            #endregion Conflicts

            if (spFolder.IsDocumentLibrary)
            {
                uint?result = SharePointService.UploadFile(siteSetting, listName, rootFolderPath, siteURL, webURL, copySource, copyDest, myByteArray, uploadItem.FieldInformations, uploadItem.ContentType, out spListItem);
                #region NotifyUploadItemInvoke

                /* This should be done before this function is called
                 * if (uploadItem.SharePointListViewControl != null && listItem != null)
                 * {
                 *  uploadItem.SharePointListViewControl.NotifyUploadItemInvoke(uploadItem.UniqueID, listItem);
                 * }
                 */
                #endregion NotifyUploadItemInvoke
                if (result.HasValue && spListItem != null)
                {
                    uploadSucceeded = true;
                }
            }
            else
            {
                int?result = SharePointService.UploadListItemWithAttachment(siteSetting, listName, rootFolderPath, uploadItem, webURL);
                uploadSucceeded = result.HasValue;
            }

            #region UploadFalied / UploadSucceeded callback

            /* This should be done before this function is called
             * if (!uploadSucceeded && UploadFailed != null) //why is UploadFailed null sometimes? JJ
             *  UploadFailed(this, new EventArgs());
             * else if (UploadSucceeded != null)
             *  UploadSucceeded(this, new EventArgs());
             */
            #endregion UploadFalied / UploadSucceeded callback
            return(uploadSucceeded);
        }