Ejemplo n.º 1
0
        private void UpdateFileFromLocation(IFileProcess fileField, IDataContext dataContext)
        {
            var fileLocation = TypeConverter.Convert<string>(LocationExpression(dataContext));
            var tempFile = FileManager.GetTempFileName(null);
            var originalFileName = DownloadFile(fileLocation, tempFile);

            string extension = null;

            if (NameExpression != null)
            {
                var fileName = TypeConverter.Convert<string>(NameExpression(dataContext));
                if (!string.IsNullOrWhiteSpace(fileName) && Path.HasExtension(fileName))
                    extension = Path.GetExtension(fileName);
            }
            else
            {
                if (!string.IsNullOrWhiteSpace(originalFileName) && Path.HasExtension(originalFileName))
                    extension = Path.GetExtension(originalFileName);
            }

            if (!string.IsNullOrEmpty(extension))
            {
                var newTempFile = Path.ChangeExtension(tempFile, extension);

                File.Move(tempFile, newTempFile);
                tempFile = newTempFile;
            }

            if (NameExpression == null)
                fileField.OriginalFileName = !string.IsNullOrEmpty(originalFileName) ? originalFileName : Path.GetFileName(tempFile);
            fileField.FileName = Path.GetFileName(tempFile);

            fileField.UploadFile();
        }
Ejemplo n.º 2
0
        private void UpdateFileFromContent(IFileProcess fileField, IDataContext dataContext)
        {
            var data = TypeConverter.Convert<byte[]>(ContentExpression(dataContext)) ?? new byte[0];

            string extension = null;

            if (NameExpression != null)
            {
                var fileName = TypeConverter.Convert<string>(NameExpression(dataContext));
                if (!string.IsNullOrWhiteSpace(fileName) && Path.HasExtension(fileName))
                    extension = Path.GetExtension(fileName);
            }

            var tempFile = FileManager.GetTempFileName(extension);

            File.WriteAllBytes(tempFile, data);

            if (NameExpression == null)
                fileField.OriginalFileName = Path.GetFileName(tempFile);
            fileField.FileName = Path.GetFileName(tempFile);

            fileField.UploadFile();
        }