void btnDelete_Click(object sender, EventArgs e) { // this is using a LinkButton which I normally never use for accessibility reasons // because linkbuttons don't work if javascript is disabled // but in this case this dialog can't work any if javascript is disabled // so I'm using one if (userCanDeleteFiles) { string fileToDelete = string.Empty; if (hdnFileUrl.Value.Length > 0) { fileToDelete = hdnFileUrl.Value; } bool canDelete = WebFolder.IsDecendentVirtualPath(rootDirectory, fileToDelete); if (canDelete) { //File.Delete(Server.MapPath(fileToDelete)); fileSystem.DeleteFile(fileToDelete); } } if ((hdnFolder.Value.Length > 0) && (hdnFolder.Value != rootDirectory)) { currentDir = hdnFolder.Value; } WebUtils.SetupRedirect(this, GetRedirectUrl()); }
private string GetCurrentDirectory() { string hiddenCurrentFolder = hdnFolder.Value; if (string.IsNullOrEmpty(hiddenCurrentFolder)) { return(rootDirectory); } if (hiddenCurrentFolder.StartsWith("/")) { hiddenCurrentFolder = "~" + hiddenCurrentFolder; } if (!fileSystem.FolderExists(hiddenCurrentFolder)) { return(rootDirectory); } if (WebFolder.IsDecendentVirtualPath(rootDirectory, hiddenCurrentFolder)) { return(hiddenCurrentFolder); } return(rootDirectory); }
public void buildWebFolder(WebFolder folder, string siteroot, string folderpath) { string destpath = siteroot + "\\" + folderpath; if (!Directory.Exists(destpath)) { Directory.CreateDirectory(destpath); } foreach (WebPage page in folder.pages) { string pagepath = destpath + "\\" + page.name; if (page.template.Length > 0 && page.content.Length > 0) { generator.generatePage(page.template, page.content, pagepath); } else { string htmlpath = website.silkroot + "\\" + folderpath + "\\" + page.name; File.Copy(htmlpath, pagepath, true); } } foreach (WebResource resource in folder.resources) { string srcpath = website.silkroot + "\\" + resource.filepath + "\\" + resource.filename; string respath = destpath + "\\" + resource.filename; File.Copy(srcpath, respath, true); } foreach (WebFolder subfolder in folder.folders) { buildWebFolder(subfolder, siteroot, folderpath + "\\" + subfolder.name); } }
public void UpdateFolder(string siteId, WebFolder folder) { try { Log.WriteStart("'{0}' UpdateFolder", ProviderSettings.ProviderName); WebProvider.UpdateFolder(siteId, folder); Log.WriteEnd("'{0}' UpdateFolder", ProviderSettings.ProviderName); } catch (Exception ex) { Log.WriteError(String.Format("'{0}' UpdateFolder", ProviderSettings.ProviderName), ex); throw; } }
private void BindFolder() { // read web site WebSite site = ES.Services.WebServers.GetWebSite(PanelRequest.ItemID); if (site == null) { RedirectToBrowsePage(); } folderPath.RootFolder = site.ContentPath; folderPath.PackageId = site.PackageId; if (String.IsNullOrEmpty(PanelRequest.Name)) { return; } // read folder WebFolder folder = ES.Services.WebServers.GetSecuredFolder(PanelRequest.ItemID, PanelRequest.Name); if (folder == null) { ReturnBack(); } txtTitle.Text = folder.Title; folderPath.SelectedFile = folder.Path; // users foreach (string user in folder.Users) { ListItem li = dlUsers.Items.FindByValue(user); if (li != null) { li.Selected = true; } } // groups foreach (string group in folder.Groups) { ListItem li = dlGroups.Items.FindByValue(group); if (li != null) { li.Selected = true; } } }
public WebFolder GetFolder(string siteId, string folderPath) { try { Log.WriteStart("'{0}' GetFolder", ProviderSettings.ProviderName); WebFolder result = WebProvider.GetFolder(siteId, folderPath); Log.WriteEnd("'{0}' GetFolder", ProviderSettings.ProviderName); return(result); } catch (Exception ex) { Log.WriteError(String.Format("'{0}' GetFolder", ProviderSettings.ProviderName), ex); throw; } }
//- tree view --------------------------------------------------------- public TreeNode AddFolder(WebFolder folder, TreeNode folderView) { TreeNode node = new TreeNode(folder.name); node.Tag = folder; node.ForeColor = Color.Blue; if (folderView == null) { siteTreeView.Nodes.Add(node); } else { folderView.Nodes.Add(node); } return(node); }
private void SaveFolder() { WebFolder folder = new WebFolder(); folder.Title = txtTitle.Text.Trim(); folder.Path = folderPath.SelectedFile; List <string> users = new List <string>(); foreach (ListItem li in dlUsers.Items) { if (li.Selected) { users.Add(li.Value); } } List <string> groups = new List <string>(); foreach (ListItem li in dlGroups.Items) { if (li.Selected) { groups.Add(li.Value); } } folder.Users = users.ToArray(); folder.Groups = groups.ToArray(); try { int result = ES.Services.WebServers.UpdateSecuredFolder(PanelRequest.ItemID, folder); if (result < 0) { ShowResultMessage(result); return; } } catch (Exception ex) { ShowErrorMessage("WEB_UPDATE_SECURED_FOLDER", ex); return; } ReturnBack(); }
public void buildSiteView(WebFolder folder, TreeNode folderView) { foreach (WebPage page in folder.pages) { spinnerView.AddPage(page, folderView); } foreach (WebResource resource in folder.resources) { spinnerView.AddResources(resource, folderView); } foreach (WebFolder f in folder.folders) { TreeNode subfolderView = spinnerView.AddFolder(f, folderView); buildSiteView(f, subfolderView); } }
private void LoadSettings() { try { // this keeps the action from changing during ajax postback in folder based sites SiteUtils.SetFormAction(Page, Request.RawUrl); } catch (MissingMethodException) { //this method was introduced in .NET 3.5 SP1 } siteSettings = CacheHelper.GetCurrentSiteSettings(); if (siteSettings == null) { return; } userCanDeleteFiles = WebUser.IsInRoles(siteSettings.RolesThatCanDeleteFilesInEditor); FileSystemProvider p = FileSystemManager.Providers[WebConfigSettings.FileSystemProvider]; if (p == null) { log.Error("Could not load file system provider " + WebConfigSettings.FileSystemProvider); return; } fileSystem = p.GetFileSystem(); if (fileSystem == null) { log.Error("Could not load file system from provider " + WebConfigSettings.FileSystemProvider); return; } rootDirectory = fileSystem.VirtualRoot; if ((WebUser.IsAdminOrContentAdmin) || (SiteUtils.UserIsSiteEditor())) { allowedExtensions = WebConfigSettings.AllowedUploadFileExtensions; regexFile.ValidationExpression = SecurityHelper.GetRegexValidationForAllowedExtensions(allowedExtensions); uploader.AcceptFileTypes = SecurityHelper.GetRegexValidationForAllowedExtensionsJqueryFileUploader(allowedExtensions); canEdit = true; userCanDeleteFiles = true; } else if (WebUser.IsInRoles(siteSettings.GeneralBrowseAndUploadRoles)) { allowedExtensions = WebConfigSettings.AllowedUploadFileExtensions; regexFile.ValidationExpression = SecurityHelper.GetRegexValidationForAllowedExtensions(allowedExtensions); uploader.AcceptFileTypes = SecurityHelper.GetRegexValidationForAllowedExtensionsJqueryFileUploader(allowedExtensions); canEdit = true; } else if (WebUser.IsInRoles(siteSettings.UserFilesBrowseAndUploadRoles)) { currentUser = SiteUtils.GetCurrentSiteUser(); if (currentUser == null) { return; } allowedExtensions = WebConfigSettings.AllowedLessPriveledgedUserUploadFileExtensions; regexFile.ValidationExpression = SecurityHelper.GetRegexValidationForAllowedExtensions(allowedExtensions); uploader.AcceptFileTypes = SecurityHelper.GetRegexValidationForAllowedExtensionsJqueryFileUploader(allowedExtensions); canEdit = true; if (!userCanDeleteFiles) { // user is not in a role that can delete files but config setting alows delete from user specific folder anyway userCanDeleteFiles = WebConfigSettings.AllowDeletingFilesFromUserFolderWithoutDeleteRole; } } resizeWidth = WebConfigSettings.ResizeImageDefaultMaxWidth; resizeHeight = WebConfigSettings.ResizeImageDefaultMaxHeight; if (!IsPostBack) { chkConstrainImageSize.Checked = WebConfigSettings.ResizeEditorUploadedImages; } pnlUpload.Visible = canEdit; if (Request.QueryString["ed"] != null) { editorType = Request.QueryString["ed"]; } string requestedType = "image"; if (Request.QueryString["type"] != null) { requestedType = Request.QueryString["type"]; } if (Request.QueryString["dir"] != null) { currentDir = Request.QueryString["dir"]; if (!WebFolder.IsDecendentVirtualPath(rootDirectory, currentDir)) { currentDir = string.Empty; } } if (Request.QueryString["CKEditor"] != null) { CKEditor = Request.QueryString["CKEditor"]; } if (Request.QueryString["CKEditorFuncNum"] != null) { CKEditorFuncNum = Request.QueryString["CKEditorFuncNum"]; } if (Request.QueryString["langCode"] != null) { langCode = Request.QueryString["langCode"]; } if (Request.QueryString["tbi"] != null) { clientTextBoxId = Request.QueryString["tbi"]; } switch (requestedType) { case "media": browserType = "media"; break; case "audio": browserType = "audio"; break; case "video": browserType = "video"; break; case "file": browserType = "file"; break; case "folder": browserType = "folder"; divFileUpload.Visible = false; //divFilePreview.Visible = false; break; case "image": default: browserType = "image"; break; } navigationRoot = SiteUtils.GetNavigationSiteRoot(); lnkRoot.Text = rootDirectory.Replace("~", string.Empty); lnkRoot.NavigateUrl = navigationRoot + "/Dialog/FileDialog.aspx?type=" + browserType; if (!Page.IsPostBack) { hdnFolder.Value = rootDirectory; if (currentDir.Length > 0) { hdnFolder.Value = currentDir; } txtMaxWidth.Text = resizeWidth.ToInvariantString(); txtMaxHeight.Text = resizeHeight.ToInvariantString(); } else { int.TryParse(txtMaxWidth.Text, out resizeWidth); int.TryParse(txtMaxHeight.Text, out resizeHeight); } imageCropperUrl = navigationRoot + "/Dialog/ImageCropperDialog.aspx"; lnkImageCropper.NavigateUrl = imageCropperUrl; if ((canEdit) && (browserType != "folder")) { string fileSystemToken = Global.FileSystemToken.ToString(); uploader.UseDropZone = WebConfigSettings.FileDialogEnableDragDrop; uploader.UploadButtonClientId = btnUpload.ClientID; uploader.ServiceUrl = navigationRoot + "/Services/FileService.ashx?cmd=uploadfromeditor&q=" + Server.UrlEncode(hdnFolder.ClientID) + "&t=" + fileSystemToken; StringBuilder refreshScript = new StringBuilder(); refreshScript.Append("function refresh() {"); refreshScript.Append("var selDir = document.getElementById('" + hdnFolder.ClientID + "').value; "); refreshScript.Append("window.location.href = updateQueryStringParameter(window.location.href,'dir',selDir); "); refreshScript.Append("} "); //string refreshFunction = "function refresh" // + " () { window.location.reload(true)'; } "; uploader.UploadCompleteCallback = "refresh"; ScriptManager.RegisterClientScriptBlock( this, this.GetType(), "refresh", refreshScript.ToString(), true); } }
public int UpdateSecuredFolder(int siteItemId, WebFolder folder) { return(WebServerController.UpdateFolder(siteItemId, folder)); }
private bool IsChildDirectory(HttpContext context, string requestedDirectory) { return(WebFolder.IsDecendentVirtualPath(fileSystem.VirtualRoot, requestedDirectory)); }
private void LoadSettings() { if (Request.QueryString["return"] != null) { returnUrl = Request.QueryString["return"]; lnkReturn.NavigateUrl = returnUrl; lnkReturn.Visible = true; } siteSettings = CacheHelper.GetCurrentSiteSettings(); if (siteSettings == null) { return; } FileSystemProvider p = FileSystemManager.Providers[WebConfigSettings.FileSystemProvider]; if (p == null) { return; } fileSystem = p.GetFileSystem(); if (fileSystem == null) { return; } rootDirectory = fileSystem.VirtualRoot; if (WebUser.IsAdminOrContentAdmin) { canEdit = true; } else if (WebUser.IsInRoles(siteSettings.GeneralBrowseAndUploadRoles)) { canEdit = true; } else if (WebUser.IsInRoles(siteSettings.UserFilesBrowseAndUploadRoles)) { canEdit = true; } if (Request.QueryString["src"] != null) { sourceImageVirtualPath = Request.QueryString["src"]; if (sourceImageVirtualPath.Length > 0) { if ((fileSystem.FileBaseUrl.Length > 0) && (sourceImageVirtualPath.StartsWith(fileSystem.FileBaseUrl))) { sourceImageVirtualPath = sourceImageVirtualPath.Substring(fileSystem.FileBaseUrl.Length); } isAllowedPath = WebFolder.IsDecendentVirtualPath(rootDirectory, sourceImageVirtualPath); sourceExists = fileSystem.FileExists(sourceImageVirtualPath); isAllowedPath = WebFolder.IsDecendentVirtualPath(rootDirectory, sourceImageVirtualPath); } } if (sourceImageVirtualPath.Length == 0) { cropper.Visible = false; return; } destImageVirtualPath = VirtualPathUtility.Combine(VirtualPathUtility.GetDirectory(sourceImageVirtualPath), Path.GetFileNameWithoutExtension(sourceImageVirtualPath) + "crop" + VirtualPathUtility.GetExtension(sourceImageVirtualPath)); SiteUtils.SetFormAction(Page, Request.RawUrl); }