Example #1
0
        public void UploadEmailAsEmlFile()
        {
            var ticket   = Session.GetTikect();
            var groupId  = string.Empty;
            var folderId = string.Empty;

            using (var folderBrowse = new BrowseFolderForm(ticket))
            {
                if (folderBrowse.ShowFolderBrowserDialog())
                {
                    groupId  = folderBrowse.Group.id;
                    folderId = folderBrowse.Folder.id;
                }
                else
                {
                    return;
                }
            }

            var fileName        = string.Format("{0}.msg", GetMailItem().Subject);
            var uploadDirectory = DFEnvironment.GetSpecialFolder(DFEnvironment.SpecialFolder.UploadDirectory);
            var uploadPath      = string.Format("{0}\\{1}", uploadDirectory, fileName);

            try
            {
                if (!Directory.Exists(uploadDirectory))
                {
                    Directory.CreateDirectory(uploadDirectory);
                }

                //Delete any file withing directory with the same name and extension.
                if (File.Exists(uploadPath))
                {
                    File.Delete(uploadPath);
                }
            }
            catch (Exception e)
            {
                LogFactory.CreateLog().LogError(e);
                throw;
            }

            //Save attach to the uploadDirectory
            GetMailItem().SaveAs(uploadPath);

            var fileInfo = new FileInfo(uploadPath);

            using (var form = new TransferProgressForm())
            {
                if (form.UploadFile(ticket, groupId, folderId, String.Empty, uploadPath, false))
                {
                    File.Delete(uploadPath);
                }
            }
        }
Example #2
0
        private string UploadFile(string ticket, string fullName)
        {
            //Step 1: Create a copy of the file and build the path to there.
            var uploadPath = string.Empty;
            var uploadDir  = DFEnvironment.GetSpecialFolder(DFEnvironment.SpecialFolder.UploadDirectory);
            var fileName   = string.Empty;

            try
            {
                if (!Directory.Exists(uploadDir))
                {
                    Directory.CreateDirectory(uploadDir);
                }

                var fileInfo = new FileInfo(fullName);

                uploadPath = string.Format("{0}\\{1}", uploadDir, fileInfo.Name);
                fileName   = fileInfo.Name;

                fileInfo.CopyTo(uploadPath, true);
            }
            catch (Exception ex)
            {
                LogFactory.CreateLog().LogError(ex);
                MessageBox.Show(ex.Message, this.Application.Name, MessageBoxButtons.YesNo,
                                MessageBoxIcon.Error);

                return(String.Empty);
            }

            //Step 3: Upload the file

            TrackingListManager.Reload();

            var trackingItem = TrackingListManager.GetByPath(fullName);

            if (trackingItem != null)
            {
                using (var form = new TransferProgressForm())
                {
                    if (form.UploadFile(ticket, trackingItem.GroupId, trackingItem.FolderId,
                                        trackingItem.FileId, uploadPath, true))
                    {
                        trackingItem.FileId       = form.FileId;
                        trackingItem.ModifiedTime = form.ModifiedTime;

                        TrackingListManager.Save();
                    }
                }
            }
            else
            {
                var community        = (UserGroup)null;
                var folder           = (FileFolder)null;
                var saveAsNewVersion = false;

                using (var saveFileView = new SaveFileForm(ticket))
                {
                    if (saveFileView.ShowSaveFileDialog())
                    {
                        community        = saveFileView.Group;
                        folder           = saveFileView.Folder;
                        saveAsNewVersion = saveFileView.SaveAsNewVersion;
                    }
                    else
                    {
                        return(String.Empty);
                    }
                }

                //Upload file to the server.
                using (var form = new TransferProgressForm())
                {
                    if (form.UploadFile(ticket, community.id,
                                        folder.id, string.Empty, uploadPath, saveAsNewVersion))
                    {
                        trackingItem = new TrackingItem()
                        {
                            Name          = Path.GetFileName(fullName),
                            LastWriteTime = DateTime.Now.ToFileTimeUtc(),
                            Path          = fullName,
                            Type          = "F",
                            GroupId       = community.id,
                            FolderId      = folder.id,
                            FileId        = form.FileId,
                            ModifiedTime  = form.ModifiedTime
                        };

                        TrackingListManager.Add(trackingItem);
                        TrackingListManager.Save();
                    }
                }
            }

            try
            {
                File.Delete(uploadPath);
            }
            catch (Exception e)
            {
                LogFactory.CreateLog().LogError(e);
            }

            return(trackingItem.FileId);
        }