public override void HandleMessage(Message message)
        {
            Assert.ArgumentNotNull(message, "message");
            base.HandleMessage(message);
            if (message.Name != "packager:endupload")
            {
                return;
            }
            string str      = message.Arguments["filename"];
            string filename = FileHandle.GetFilename(str);

            if (!string.IsNullOrEmpty(filename))
            {
                str = filename;
            }
            this.EndUploading(Path.GetFileName(str));
        }
Esempio n. 2
0
        protected override void OnLoad(EventArgs e)
        {
            Assert.ArgumentNotNull(e, "e");
            base.OnLoad(e);
            string text = StringUtil.GetString(new string[]
            {
                base.Request.QueryString["file"]
            });
            bool   flag     = false;
            string filename = FileHandle.GetFilename(text);

            if (!string.IsNullOrEmpty(filename))
            {
                text = filename;
                flag = true;
            }
            if (!string.IsNullOrEmpty(text))
            {
                #region this code has been added to fix 90534
                PageScriptManager pageScriptManager = this.Context.Items["sc_pagescriptmanager"] as PageScriptManager;
                if (pageScriptManager != null)
                {
                    pageScriptManager.AddStylesheets = false;
                }
                #endregion
                if (MediaManager.IsMediaUrl(text))
                {
                    this.DownloadMediaFile(text);
                    return;
                }
                if (text.IndexOf("id=", StringComparison.OrdinalIgnoreCase) >= 0)
                {
                    this.DownloadMediaById(text);
                    return;
                }
                if (flag || Sitecore.Context.IsAdministrator)
                {
                    this.DownloadFile(text);
                }
            }
        }
        protected override void OnLoad(EventArgs e)
        {
            Assert.ArgumentNotNull(e, "e");
            base.OnLoad(e);
            if (this.IsEvent || this.Request.Files.Count <= 0)
            {
                return;
            }
            string filename = FileHandle.GetFilename(this.Request.Form["Path"]);

            if (string.IsNullOrEmpty(filename))
            {
                SecurityException securityException = new SecurityException("Upload path invalid");
                Log.Error("File upload handle not found. Handle: " + this.Request.Form["Path"], securityException, this);
                throw securityException;
            }
            var string1 = StringUtil.GetString(new []
            {
                filename
            });
            string string2 = StringUtil.GetString(new []
            {
                this.Request.Form["Item"]
            });
            string string3 = StringUtil.GetString(new []
            {
                this.Request.Form["Language"]
            });
            bool flag1 = StringUtil.GetString(new []
            {
                this.Request.Form["Overwrite"]
            }) == "1";
            bool flag2 = StringUtil.GetString(new []
            {
                this.Request.Form["Unzip"]
            }) == "1";
            bool flag3 = StringUtil.GetString(new []
            {
                this.Request.Form["Versioned"]
            }) == "1";

            UploadArgs args = new UploadArgs
            {
                Files = this.Request.Files
            };

            if (!string.IsNullOrEmpty(string2))
            {
                args.Folder      = string2;
                args.Destination = UploadDestination.Database;
            }
            else
            {
                args.Folder      = string1;
                args.Destination = UploadDestination.File;
                this.SetFileOnlyIfExists(args);
            }
            args.Overwrite             = flag1;
            args.Unpack                = flag2;
            args.Versioned             = flag3;
            args.Language              = Language.Parse(string3);
            args.Parameters["message"] = "packager:endupload";
            PipelineFactory.GetPipeline("uiUpload").Start(args);
        }
Esempio n. 4
0
 protected override void OnLoad(EventArgs e)
 {
     base.OnLoad(e);
     if (MaxRequestLengthExceeded)
     {
         HttpContext.Current.Response.Write(
             "<html><head><script type=\"text/JavaScript\" language=\"javascript\">window.top.scForm.getTopModalDialog().frames[0].scForm.postRequest(\"\", \"\", \"\", 'ShowFileTooBig()')</script></head><body>Done</body></html>");
     }
     else
     {
         if (IsEvent)
         {
             return;
         }
         if (Request.Files.Count <= 0)
         {
             return;
         }
         try
         {
             var pathOrId = Sitecore.Context.ClientPage.ClientRequest.Form["ItemUri"];
             var langStr  = Sitecore.Context.ClientPage.ClientRequest.Form["LanguageName"];
             var language = langStr.Length > 0
                 ? LanguageManager.GetLanguage(langStr) ?? Sitecore.Context.ContentLanguage
                 : Sitecore.Context.ContentLanguage;
             var itemUri    = ItemUri.Parse(pathOrId);
             var uploadArgs = new UploadArgs();
             if (itemUri != null)
             {
                 pathOrId = itemUri.GetPathOrId();
                 uploadArgs.Destination = Settings.Media.UploadAsFiles
                     ? UploadDestination.File
                     : UploadDestination.Database;
             }
             else
             {
                 uploadArgs.Destination = UploadDestination.File;
                 uploadArgs.FileOnly    = true;
             }
             uploadArgs.Files     = Request.Files;
             uploadArgs.Folder    = pathOrId;
             uploadArgs.Overwrite = Sitecore.Context.ClientPage.ClientRequest.Form["Overwrite"].Length > 0;
             //uploadArgs.Overwrite = Settings.Upload.SimpleUploadOverwriting;
             uploadArgs.Unpack    = Sitecore.Context.ClientPage.ClientRequest.Form["Unpack"].Length > 0;
             uploadArgs.Versioned = Sitecore.Context.ClientPage.ClientRequest.Form["Versioned"].Length > 0;
             //uploadArgs.Versioned = Settings.Media.UploadAsVersionableByDefault;
             uploadArgs.Language         = language;
             uploadArgs.CloseDialogOnEnd = false;
             PipelineFactory.GetPipeline("uiUpload").Start(uploadArgs);
             string fileName;
             if (uploadArgs.UploadedItems.Count > 0)
             {
                 fileName = uploadArgs.UploadedItems[0].ID.ToString();
                 LogUtils.Audit(this, "Upload: {0}", StringUtil.Join(uploadArgs.UploadedItems, ", ", "Name"));
             }
             else
             {
                 var fileHandle = uploadArgs.Properties["filename"];
                 if (fileHandle != null)
                 {
                     fileName = WebUtil.UrlEncode(FileHandle.GetFilename(fileHandle.ToString()));
                 }
                 else if (uploadArgs.Unpack)
                 {
                     fileName = WebUtil.UrlEncode(uploadArgs.Folder);
                 }
                 else
                 {
                     fileName = string.Empty;
                 }
             }
             if (!string.IsNullOrEmpty(uploadArgs.ErrorText))
             {
                 return;
             }
             HttpContext.Current.Response.Write(
                 "<html><head><script type=\"text/JavaScript\" language=\"javascript\">window.top.scForm.getTopModalDialog().frames[0].scForm.postRequest(\"\", \"\", \"\", 'EndUploading(\"" +
                 fileName + "\")')</script></head><body>Done</body></html>");
         }
         catch (OutOfMemoryException)
         {
             HttpContext.Current.Response.Write(
                 "<html><head><script type=\"text/JavaScript\" language=\"javascript\">window.top.scForm.getTopModalDialog().frames[0].scForm.postRequest(\"\", \"\", \"\", 'ShowFileTooBig(" +
                 StringUtil.EscapeJavascriptString(Request.Files[0].FileName) +
                 ")')</script></head><body>Done</body></html>");
         }
         catch (Exception ex)
         {
             if (ex.InnerException is OutOfMemoryException)
             {
                 HttpContext.Current.Response.Write(
                     "<html><head><script type=\"text/JavaScript\" language=\"javascript\">window.top.scForm.getTopModalDialog().frames[0].scForm.postRequest(\"\", \"\", \"\", 'ShowFileTooBig(" +
                     StringUtil.EscapeJavascriptString(Request.Files[0].FileName) +
                     ")')</script></head><body>Done</body></html>");
             }
             else
             {
                 HttpContext.Current.Response.Write(
                     "<html><head><script type=\"text/JavaScript\" language=\"javascript\">window.top.scForm.getTopModalDialog().frames[0].scForm.postRequest(\"\", \"\", \"\", 'ShowError')</script></head><body>Done</body></html>");
             }
         }
     }
 }