Exemplo n.º 1
0
        private static bool CanCompineFiles(HttpPostedFileBase[] UploadedFiles, out byte[] Result, out string contentType)
        {
            contentType = string.Empty;
            Result      = null;
            try
            {
                if (UploadedFiles == null)
                {
                    return(false);
                }


                if (UploadedFiles.Count() == 1 /*!Images[0].ContentType.Contains("doc")*/)
                {
                    Constants.Enumerations.UploadFileTypesEnum FileType = GetFileType(UploadedFiles[0]);
                    if (FileType == Constants.Enumerations.UploadFileTypesEnum.Pdf || FileType == Constants.Enumerations.UploadFileTypesEnum.Image)
                    {
                        contentType = UploadedFiles[0].ContentType.Replace("application/octet-stream", "image/jpeg");
                        Result      = ImageProcesses.ReadFully(UploadedFiles[0].InputStream);
                        return(false);
                    }
                }

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Exemplo n.º 2
0
        public List <Error> UploadOneFile(string Source, string SourceId)
        {
            List <Error> errors    = new List <Error>();
            var          imageData = _hrUnitOfWork.MissionRepository.GetBytes(int.Parse(SourceId));

            if (imageData != null)
            {
                return(errors);
            }
            var      file     = HttpContext.Request.Files[0];
            int      sid      = Convert.ToInt32(SourceId);
            var      stream   = ImageProcesses.ReadFully(file.InputStream);
            WebImage fullsize = null;
            WebImage thumbs   = null;

            fullsize = new WebImage(stream).Resize(1240, 1754);
            thumbs   = new WebImage(stream).Resize(124, 175);

            CompanyDocsViews doc = new CompanyDocsViews()
            {
                CompanyId   = CompanyId,
                name        = file.FileName,
                CreatedUser = UserName,
                Source      = Source,
                SourceId    = sid,
                file_stream = fullsize != null?fullsize.GetBytes() : stream,
                                  thumbs = thumbs != null?thumbs.GetBytes() : null
            };

            _hrUnitOfWork.CompanyRepository.Add(doc);
            errors = Save(Language);
            return(errors);
        }
Exemplo n.º 3
0
        //private static void CovertWordToPDF(HttpPostedFileBase wordFile, string CurrentWordFullPath, string NewPdfFullPath)
        //{

        //    try
        //    {
        //        // Create a new Microsoft Word application object
        //        Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();

        //        // C# doesn't have optional arguments so we'll need a dummy value
        //        object oMissing = System.Reflection.Missing.Value;

        //        word.Visible = false;
        //        word.ScreenUpdating = false;

        //        wordFile.SaveAs(CurrentWordFullPath);

        //        // Cast as Object for word Open method
        //        Object filename = (Object)CurrentWordFullPath;

        //        // Use the dummy value as a placeholder for optional arguments
        //        Microsoft.Office.Interop.Word.Document doc = word.Documents.Open(ref filename, ref oMissing,
        //            ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
        //            ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
        //            ref oMissing, ref oMissing, ref oMissing, ref oMissing);
        //        doc.Activate();

        //        // NewPdfFullPath = CurrentWordFullPath.Replace(".docx", ".pdf").Replace(".doc", ".pdf");
        //        object outputFileName = (object)NewPdfFullPath;
        //        object fileFormat = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatPDF;

        //        // Save document into PDF Format
        //        doc.SaveAs(ref outputFileName,
        //            ref fileFormat, ref oMissing, ref oMissing,
        //            ref oMissing, ref oMissing, ref oMissing, ref oMissing,
        //            ref oMissing, ref oMissing, ref oMissing, ref oMissing,
        //            ref oMissing, ref oMissing, ref oMissing, ref oMissing);

        //        // Close the Word document, but leave the Word application open.
        //        // doc has to be cast to type _Document so that it will find the
        //        // correct Close method.
        //        object saveChanges = Microsoft.Office.Interop.Word.WdSaveOptions.wdDoNotSaveChanges;
        //        ((Microsoft.Office.Interop.Word._Document)doc).Close(ref saveChanges, ref oMissing, ref oMissing);
        //        doc = null;

        //        // word has to be cast to type _Application so that it will find
        //        // the correct Quit method.
        //        ((Microsoft.Office.Interop.Word._Application)word).Quit(ref oMissing, ref oMissing, ref oMissing);
        //        word = null;
        //    }
        //    catch
        //    {

        //    }
        //}


        private static void ReadBytes_ContentType(string FullPath, out byte[] Result, out string contentType)
        {
            Result      = null;
            contentType = string.Empty;
            try
            {
                FileStream fStream = new FileStream(FullPath, FileMode.Open, FileAccess.Read);
                contentType = MimeMapping.GetMimeMapping(FullPath);
                Result      = ImageProcesses.ReadFully(fStream);
                fStream.Close();
            }
            catch
            {
            }
        }