public bool DisposeHandle(UrlHandle handle) { return(UrlHandle.DisposeHandle(handle)); }
protected override void OnLoad(EventArgs e) { Assert.ArgumentNotNull(e, "e"); Assert.IsTrue(ServiceAuthorizationManager.IsUserAuthorized(WebServiceSettings.ServiceExecution, Context.User.Name, false), "Application access denied."); base.OnLoad(e); Context.ClientPage.ClientResponse.SetDialogValue(Hidden.Value); if (Context.ClientPage.IsEvent) { return; } UrlHandle handle = null; if (!UrlHandle.TryGetHandle(out handle)) { FileNameLabel.Text = "Invalid dialog invocation."; SizeLabel.Visible = false; PathPrefix.Visible = false; SizePrefix.Visible = false; OK.Visible = false; DownloadImage.Visible = false; ErrorImage.Visible = true; return; } FileName = handle["fn"]; ItemUri = handle["uri"]; ItemDb = handle["db"]; bool showFullPath; if (!bool.TryParse(handle["fp"], out showFullPath)) { showFullPath = false; } Text.Text = handle["te"]; if (!string.IsNullOrEmpty(ItemUri)) { var item = Factory.GetDatabase(ItemDb).GetItem(new DataUri(ItemUri)); if (MediaManager.HasMediaContent(item)) { FileNameLabel.Text = (showFullPath ? item.GetProviderPath() : item.Name) + "." + item["Extension"]; long size; SizeLabel.Text = Int64.TryParse(item["size"], out size) ? ToFileSize(size) : "unknown"; } else { SheerResponse.Alert("There is no file attached."); } } else if (!string.IsNullOrEmpty(FileName)) { // check if file in approved location var filePath = FileUtil.MapPath(FileName); var webSitePath = FileUtil.MapPath("/"); var dataPath = FileUtil.MapPath(Settings.DataFolder); if (!filePath.StartsWith(webSitePath, StringComparison.InvariantCultureIgnoreCase) && !filePath.StartsWith(dataPath, StringComparison.InvariantCultureIgnoreCase)) { FileNameLabel.Text = "Files from outside of the Sitecore Data and Website folders cannot be downloaded.\n\n" + "Copy the file to the Sitecore Data folder and try again."; SizeLabel.Visible = false; PathPrefix.Visible = false; SizePrefix.Visible = false; OK.Visible = false; DownloadImage.Visible = false; ErrorImage.Visible = true; return; } FileNameLabel.Text = showFullPath ? FileName : Path.GetFileName(FileName); SheerResponse.Download(FileName); Hidden.Value = "downloaded"; var file = new FileInfo(FileName); SizeLabel.Text = ToFileSize(file.Length); } var caption = handle["cp"]; Context.ClientPage.Title = caption; Assert.ArgumentNotNull(e, "e"); base.OnLoad(e); Text.Text = handle["te"]; Hidden.Value = "cancelled"; Context.ClientPage.ClientResponse.SetDialogValue(Hidden.Value); UrlHandle.DisposeHandle(handle); }