private string SaveFileToTempDirectory(FileUpload fileToRestore)
        {
            // Save file to temp directory, ensuring that we are not overwriting an existing file. If the uploaded file is a ZIP archive,
            // extract the embedded XML file and save that.
            var filePath = String.Empty;

            var fileExt = Path.GetExtension(fileToRestore.FileName);

            if (fileExt == null || String.IsNullOrWhiteSpace(fileExt))
            {
                return(filePath);
            }

            if (fileExt.Equals(".zip", StringComparison.OrdinalIgnoreCase))
            {
                using (var zip = new ZipUtility(Utils.UserName, GetGalleryServerRolesForUser()))
                {
                    filePath = zip.ExtractNextFileFromZip(fileToRestore.FileContent, AppSetting.Instance.TempUploadDirectory);
                }
            }
            else if (fileExt.Equals(".xml", StringComparison.OrdinalIgnoreCase))
            {
                string fileName = HelperFunctions.ValidateFileName(AppSetting.Instance.TempUploadDirectory, fileToRestore.FileName);
                filePath = Path.Combine(AppSetting.Instance.TempUploadDirectory, fileName);

                fileToRestore.SaveAs(filePath);
            }

            return(filePath);
        }
Beispiel #2
0
        private static string SaveFileToTempDirectory(FileUpload fileToRestore)
        {
            // Save file to temp directory, ensuring that we are not overwriting an existing file. If the uploaded file is a ZIP archive,
            // extract the embedded XML file and save that.
            string filePath;

            if (Path.GetExtension(fileToRestore.FileName).Equals(".zip", StringComparison.OrdinalIgnoreCase))
            {
                ZipUtility zip = new ZipUtility(Util.UserName, RoleController.GetGalleryServerRolesForUser());

                filePath = zip.ExtractNextFileFromZip(fileToRestore.FileContent, AppSetting.Instance.TempUploadDirectory);
            }
            else
            {
                string fileName = HelperFunctions.ValidateFileName(AppSetting.Instance.TempUploadDirectory, fileToRestore.FileName);
                filePath = Path.Combine(AppSetting.Instance.TempUploadDirectory, fileName);

                fileToRestore.SaveAs(filePath);
            }

            return(filePath);
        }