protected void BtnEdit_Click(object sender, EventArgs e) { var templateName = (sender as Button).CommandArgument; var contextNode = PortalContext.Current.ContextNode; var templateNode = contextNode.GetReference<Node>(string.Concat(templateName, "Page")); var templateNodePath = templateNode.Path; if (templateNodePath.Contains("System/SystemPlugins")) { var targetPath = RepositoryPath.Combine(contextNode.Path, "configuration"); if (!Node.Exists(targetPath)) { var folder = new Folder(contextNode, "Folder") { Name = "configuration", DisplayName = "Configuration" }; folder.Save(); } var wcd = NodeType.CreateInstance("WebContentDemo", Node.LoadNode(targetPath)); wcd["Name"] = templateNode["Name"]; wcd["DisplayName"] = templateNode["DisplayName"]; wcd["Subtitle"] = templateNode["Subtitle"]; wcd["Body"] = templateNode["Body"]; wcd.Save(); templateNodePath = wcd.Path; contextNode.SetReference(string.Concat(templateName, "Page"), wcd); contextNode.Save(); } Response.Redirect(ActionFramework.GetActionUrl(templateNodePath, "EditSurveyTemplate", PortalContext.Current.BackUrl)); }
public void HandleMethod() { var parentPath = RepositoryPath.GetParentPath(_handler.GlobalPath); var folderName = RepositoryPath.GetFileName(_handler.GlobalPath); try { var f = new Folder(Node.LoadNode(parentPath)) { Name = folderName }; f.Save(); _handler.Context.Response.StatusCode = 201; } catch (SecurityException e) //logged { Logger.WriteException(e); _handler.Context.Response.StatusCode = 403; } catch (SenseNetSecurityException ee) //logged { Logger.WriteException(ee); _handler.Context.Response.StatusCode = 403; } catch (Exception eee) //logged { Logger.WriteException(eee); _handler.Context.Response.StatusCode = 405; } _handler.Context.Response.Flush(); }
private static Node GetParent(Node contextNode) { var parent = Node.LoadNode(RepositoryPath.Combine(contextNode.Path, "Workflows/MailProcess")); if (parent == null) { var workflows = Node.LoadNode(RepositoryPath.Combine(contextNode.Path, "Workflows")); if (workflows == null) { using (new SystemAccount()) { workflows = new SystemFolder(contextNode); workflows.Name = "Workflows"; try { workflows.Save(); } catch (Exception ex) { Logger.WriteException(ex, ExchangeHelper.ExchangeLogCategory); return(null); } } } using (new SystemAccount()) { parent = new SenseNet.ContentRepository.Folder(workflows); parent.Name = "MailProcess"; try { parent.Save(); } catch (Exception ex) { Logger.WriteException(ex, ExchangeHelper.ExchangeLogCategory); return(null); } } } return(parent); }
public ActionResult CopyAppLocal(string nodepath, string apppath, string back) { AssertPermission(); nodepath = HttpUtility.UrlDecode(nodepath); apppath = HttpUtility.UrlDecode(apppath); back = HttpUtility.UrlDecode(back); var targetAppPath = RepositoryPath.Combine(nodepath, "(apps)"); var targetThisPath = RepositoryPath.Combine(targetAppPath, "This"); //we don't use the system account here, the user must have create rights here if (!Node.Exists(targetAppPath)) { var apps = new SystemFolder(Node.LoadNode(nodepath)) {Name = "(apps)"}; apps.Save(); } if (!Node.Exists(targetThisPath)) { var thisFolder = new Folder(Node.LoadNode(targetAppPath)) { Name = "This" }; thisFolder.Save(); } try { Node.Copy(apppath, targetThisPath); } catch (Exception ex) { Logger.WriteException(ex); } return this.Redirect(back); }
private static Node GetParent(Node contextNode) { var parent = Node.LoadNode(RepositoryPath.Combine(contextNode.Path, "Workflows/MailProcess")); if (parent == null) { var workflows = Node.LoadNode(RepositoryPath.Combine(contextNode.Path, "Workflows")); if (workflows == null) { using (new SystemAccount()) { workflows = new SystemFolder(contextNode); workflows.Name = "Workflows"; try { workflows.Save(); } catch (Exception ex) { Logger.WriteException(ex, ExchangeHelper.ExchangeLogCategory); return null; } } } using (new SystemAccount()) { parent = new SenseNet.ContentRepository.Folder(workflows); parent.Name = "MailProcess"; try { parent.Save(); } catch (Exception ex) { Logger.WriteException(ex, ExchangeHelper.ExchangeLogCategory); return null; } } } return parent; }
public void FieldValidation_Reference() { //Assert.Inconclusive("Missing validation message"); ContentTypeInstaller.InstallContentType(@"<?xml version='1.0' encoding='utf-8'?> <ContentType name='ReferredContent' parentType='GenericContent' handler='SenseNet.ContentRepository.GenericContent' xmlns='http://schemas.sensenet.com/SenseNet/ContentRepository/ContentTypeDefinition'> <Fields> <Field name='ReferenceTest' type='Reference'> <Configuration> <AllowMultiple>true</AllowMultiple> </Configuration> </Field> </Fields> </ContentType>"); var c = SNC.Content.CreateNew("Folder", _testRoot, "RefFieldTests"); c.Save(); var testFolder = Node.Load<Folder>(c.Id); SNC.Content.CreateNew("ReferredContent", testFolder, "Referred1").Save(); SNC.Content.CreateNew("ReferredContent", testFolder, "Referred2").Save(); SNC.Content referrer; //==== one, null, no type, no path, no query ContentTypeInstaller.InstallContentType(@"<?xml version='1.0' encoding='utf-8'?> <ContentType name='ValidatedContent' parentType='GenericContent' handler='SenseNet.ContentRepository.GenericContent' xmlns='http://schemas.sensenet.com/SenseNet/ContentRepository/ContentTypeDefinition' xmlns:q='http://schemas.sensenet.com/SenseNet/ContentRepository/SearchExpression'> <Fields> <Field name='ReferenceTest' type='Reference'></Field> </Fields> </ContentType>"); referrer = SNC.Content.CreateNew("ValidatedContent", testFolder, "Referrer"); Assert.IsTrue(referrer.IsValid, "one, null, no type, no path, no query #101"); referrer["ReferenceTest"] = testFolder.Children.ToArray<Node>()[0]; Assert.IsTrue(referrer.IsValid, "one, null, no type, no path, no query #102"); referrer["ReferenceTest"] = testFolder.Children; Assert.IsFalse(referrer.IsValid, "one, null, no type, no path, no query #103"); //==== one, not null, no type, no path, no query ContentTypeInstaller.InstallContentType(@"<?xml version='1.0' encoding='utf-8'?> <ContentType name='ValidatedContent' parentType='GenericContent' handler='SenseNet.ContentRepository.GenericContent' xmlns='http://schemas.sensenet.com/SenseNet/ContentRepository/ContentTypeDefinition' xmlns:q='http://schemas.sensenet.com/SenseNet/ContentRepository/SearchExpression'> <Fields> <Field name='ReferenceTest' type='Reference'> <Configuration> <Compulsory>true</Compulsory> </Configuration> </Field> </Fields> </ContentType>"); referrer = SNC.Content.CreateNew("ValidatedContent", testFolder, "Referrer"); Assert.IsFalse(referrer.IsValid, "one, not null, no type, no path, no query #111"); referrer["ReferenceTest"] = testFolder.Children.ToArray<Node>()[0]; Assert.IsTrue(referrer.IsValid, "one, not null, no type, no path, no query #112"); referrer["ReferenceTest"] = testFolder.Children; Assert.IsFalse(referrer.IsValid, "one, not null, no type, no path, no query #113"); //==== multi, null, no type, no path, no query ContentTypeInstaller.InstallContentType(@"<?xml version='1.0' encoding='utf-8'?> <ContentType name='ValidatedContent' parentType='GenericContent' handler='SenseNet.ContentRepository.GenericContent' xmlns='http://schemas.sensenet.com/SenseNet/ContentRepository/ContentTypeDefinition' xmlns:q='http://schemas.sensenet.com/SenseNet/ContentRepository/SearchExpression'> <Fields> <Field name='ReferenceTest' type='Reference'> <Configuration> <AllowMultiple>true</AllowMultiple> </Configuration> </Field> </Fields> </ContentType>"); referrer = SNC.Content.CreateNew("ValidatedContent", testFolder, "Referrer"); Assert.IsTrue(referrer.IsValid, "multi, null, no type, no path, no query #121"); referrer["ReferenceTest"] = testFolder.Children.ToArray<Node>()[0]; Assert.IsTrue(referrer.IsValid, "multi, null, no type, no path, no query #122"); referrer["ReferenceTest"] = testFolder.Children; Assert.IsTrue(referrer.IsValid, "multi, null, no type, no path, no query #123"); //==== multi, not null, no type, no path, no query ContentTypeInstaller.InstallContentType(@"<?xml version='1.0' encoding='utf-8'?> <ContentType name='ValidatedContent' parentType='GenericContent' handler='SenseNet.ContentRepository.GenericContent' xmlns='http://schemas.sensenet.com/SenseNet/ContentRepository/ContentTypeDefinition' xmlns:q='http://schemas.sensenet.com/SenseNet/ContentRepository/SearchExpression'> <Fields> <Field name='ReferenceTest' type='Reference'> <Configuration> <AllowMultiple>true</AllowMultiple> <Compulsory>true</Compulsory> </Configuration> </Field> </Fields> </ContentType>"); referrer = SNC.Content.CreateNew("ValidatedContent", testFolder, "Referrer"); Assert.IsFalse(referrer.IsValid, "multi, not null, no type, no path, no query #131"); referrer["ReferenceTest"] = testFolder.Children.ToArray<Node>()[0]; Assert.IsTrue(referrer.IsValid, "multi, not null, no type, no path, no query #132"); referrer["ReferenceTest"] = testFolder.Children; Assert.IsTrue(referrer.IsValid, "multi, not null, no type, no path, no query #133"); //==== multi, null, type, no path, no query ContentTypeInstaller.InstallContentType(@"<?xml version='1.0' encoding='utf-8'?> <ContentType name='ValidatedContent' parentType='GenericContent' handler='SenseNet.ContentRepository.GenericContent' xmlns='http://schemas.sensenet.com/SenseNet/ContentRepository/ContentTypeDefinition' xmlns:q='http://schemas.sensenet.com/SenseNet/ContentRepository/SearchExpression'> <Fields> <Field name='ReferenceTest' type='Reference'> <Configuration> <AllowMultiple>true</AllowMultiple> <AllowedTypes> <Type>ReferredContent</Type> </AllowedTypes> </Configuration> </Field> </Fields> </ContentType>"); referrer = SNC.Content.CreateNew("ValidatedContent", testFolder, "Referrer"); Assert.IsTrue(referrer.IsValid, "multi, null, type, no path, no query #141"); referrer["ReferenceTest"] = testFolder.Children.ToArray<Node>()[0]; Assert.IsTrue(referrer.IsValid, "multi, null, type, no path, no query #142"); referrer["ReferenceTest"] = testFolder.Children; Assert.IsTrue(referrer.IsValid, "multi, null, type, no path, no query #143"); //-- create content with restricted type SNC.Content.CreateNew("ValidatedContent", testFolder, "AnotherReferrer").Save(); referrer["ReferenceTest"] = testFolder.Children; Assert.IsFalse(referrer.IsValid, "multi, null, type, no path, no query #144"); //-- allow ValidatedContent type ContentTypeInstaller.InstallContentType(@"<?xml version='1.0' encoding='utf-8'?> <ContentType name='ValidatedContent' parentType='GenericContent' handler='SenseNet.ContentRepository.GenericContent' xmlns='http://schemas.sensenet.com/SenseNet/ContentRepository/ContentTypeDefinition' xmlns:q='http://schemas.sensenet.com/SenseNet/ContentRepository/SearchExpression'> <Fields> <Field name='ReferenceTest' type='Reference'> <Configuration> <AllowMultiple>true</AllowMultiple> <AllowedTypes> <Type>ReferredContent</Type> <Type>ValidatedContent</Type> </AllowedTypes> </Configuration> </Field> </Fields> </ContentType>"); referrer = SNC.Content.CreateNew("ValidatedContent", testFolder, "Referrer"); referrer["ReferenceTest"] = testFolder.Children; Assert.IsTrue(referrer.IsValid, "multi, null, type, no path, no query #145"); //==== multi, null, no type, path, no query Folder subFolder = new Folder(testFolder); subFolder.Name = "SubFolder"; subFolder.Save(); string subFolderPath = subFolder.Path; SNC.Content.CreateNew("ReferredContent", subFolder, "Referred3").Save(); SNC.Content.CreateNew("ReferredContent", subFolder, "Referred4").Save(); ContentTypeInstaller.InstallContentType(@"<?xml version='1.0' encoding='utf-8'?> <ContentType name='ValidatedContent' parentType='GenericContent' handler='SenseNet.ContentRepository.GenericContent' xmlns='http://schemas.sensenet.com/SenseNet/ContentRepository/ContentTypeDefinition' xmlns:q='http://schemas.sensenet.com/SenseNet/ContentRepository/SearchExpression'> <Fields> <Field name='ReferenceTest' type='Reference'> <Configuration> <AllowMultiple>true</AllowMultiple> <SelectionRoot> <Path>" + subFolderPath + @"</Path> </SelectionRoot> </Configuration> </Field> </Fields> </ContentType>"); referrer = SNC.Content.CreateNew("ValidatedContent", testFolder, "Referrer"); Assert.IsTrue(referrer.IsValid, "multi, null, no type, path, no query #151"); referrer["ReferenceTest"] = testFolder.Children.ToArray<Node>()[0]; Assert.IsFalse(referrer.IsValid, "multi, null, no type, path, no query #152"); referrer["ReferenceTest"] = testFolder.Children; Assert.IsFalse(referrer.IsValid, "multi, null, no type, path, no query #153"); referrer["ReferenceTest"] = subFolder.Children.ToArray<Node>()[0]; Assert.IsTrue(referrer.IsValid, "multi, null, no type, path, no query #154"); referrer["ReferenceTest"] = subFolder.Children; Assert.IsTrue(referrer.IsValid, "multi, null, no type, path, no query #155"); //==== multi, null, no type, no path, query ContentTypeInstaller.InstallContentType(@"<?xml version='1.0' encoding='utf-8'?> <ContentType name='ValidatedContent' parentType='GenericContent' handler='SenseNet.ContentRepository.GenericContent' xmlns='http://schemas.sensenet.com/SenseNet/ContentRepository/ContentTypeDefinition' xmlns:q='http://schemas.sensenet.com/SenseNet/ContentRepository/SearchExpression'> <Fields> <Field name='ReferenceTest' type='Reference'> <Configuration> <AllowMultiple>true</AllowMultiple> <Query> <q:And> <q:String op='EndsWith' property='Name'>2</q:String> </q:And> </Query> </Configuration> </Field> </Fields> </ContentType>"); var goodList = NodeQuery.Parse(@"<q:SearchExpression xmlns:q='http://schemas.sensenet.com/SenseNet/ContentRepository/SearchExpression'> <q:And> <q:String op='EndsWith' property='Name'>2</q:String> </q:And> </q:SearchExpression>").Execute().Nodes; referrer = SNC.Content.CreateNew("ValidatedContent", testFolder, "Referrer"); Assert.IsTrue(referrer.IsValid, "multi, null, no type, path, no query #161"); referrer["ReferenceTest"] = testFolder.Children; Assert.IsFalse(referrer.IsValid, "multi, null, no type, path, no query #162"); referrer["ReferenceTest"] = subFolder.Children; Assert.IsFalse(referrer.IsValid, "multi, null, no type, path, no query #163"); referrer["ReferenceTest"] = goodList; Assert.IsTrue(referrer.IsValid, "multi, null, no type, path, no query #164"); Node node = Node.LoadNode(123); }
private static Node EnsureFolder(string path) { var node = Node.LoadNode(path); if (node != null) return node; var parentPath = ContentManager.Path.GetParentPath(path); var folderName = ContentManager.Path.GetFileName(path); var parent = EnsureFolder(parentPath); var folder = new Folder(parent); folder.Name = folderName; folder.Save(); return folder; }
public static void EnsurePath(string path) { if (!Node.Exists(path)) { var parentPath = RepositoryPath.GetParentPath(path); EnsurePath(parentPath); Folder folder = new Folder(Node.LoadNode(parentPath)); folder.Name = RepositoryPath.GetFileName(path); folder.Save(); } }
public string CreateFolder(string url) { // This operation creates a folder in the document library of the current Document Workspace site. // If the parent folder for the specified URL does not exist, the protocol server MUST return an Error element with a FolderNotFound error code. // If the specified URL already exists, the protocol server MUST return an Error element with an AlreadyExists error code. // If the user does not have sufficient access permissions to create the folder, the protocol server MUST return an Error element with a NoAccess error code. // The protocol server MUST return an Error element with a Failed or a ServerFailure error code if an unspecified error prevents creating the specified folder. // If none of the prior conditions apply, the protocol server MUST create the folder specified in the CreateFolder element. WriteDebug("CreateFolder"); if (DwsHelper.CheckVisitor()) return null; if (string.IsNullOrEmpty(url)) return "<Error>FolderNotFound</Error>"; var sepIndex = url.IndexOf(RepositoryPath.PathSeparator); var folderName = sepIndex < 0 ? url : url.Substring(sepIndex + 1); if (string.IsNullOrEmpty(folderName)) return "<Error>FolderNotFound</Error>"; var parentPath = sepIndex < 1 ? this.RequestPath : RepositoryPath.Combine(this.RequestPath, url.Substring(0, sepIndex)); var folderPath = RepositoryPath.Combine(parentPath, folderName); if (Node.Exists(folderPath)) return "<Error>AlreadyExists</Error>"; var parent = Node.Load<Node>(parentPath); if (parent == null) return "<Error>FolderNotFound</Error>"; var folder = new Folder(parent) { Name = folderName }; try { folder.Save(); } catch (SenseNetSecurityException ex) { Logger.WriteException(ex); return "<Error>NoAccess</Error>"; } catch (Exception ex) { Logger.WriteException(ex); return "<Error>Failed</Error>"; } return "<Result />"; // Folder has been successfully created. }
private void SaveFile() { // get target container var container = PortalContext.Current.ContextNode as GenericContent; var targetFolderName = HttpContext.Current.Request["TargetFolder"]; if (!string.IsNullOrEmpty(targetFolderName)) { var containerPath = RepositoryPath.Combine(container.Path, targetFolderName); container = Node.LoadNode(containerPath) as GenericContent; // create target container if does not exist if (container == null) { using (new SystemAccount()) { container = new Folder(PortalContext.Current.ContextNode); container.Name = targetFolderName; container.AllowedChildTypes = AllowedContentTypesList; container.Save(); } } } var contentTypeName = UploadHelper.GetContentType(Upload.PostedFile.FileName, null) ?? "File"; var allowed = UploadHelper.CheckAllowedContentType(container as GenericContent, contentTypeName); if (allowed) { var binaryData = UploadHelper.CreateBinaryData(Upload.PostedFile); var fileName = binaryData.FileName.ToString(); var content = SenseNet.ContentRepository.Content.CreateNew(contentTypeName, container, fileName); content.ContentHandler.AllowIncrementalNaming = true; // uploaded files of users go to the same folder. avoid collision, do not overwrite files of each other content["Name"] = fileName; content.Fields["Binary"].SetData(binaryData); content.Save(); // display uploaded file in repeater if (_fileListElements == null) _fileListElements = new List<FileListElement>(); _fileListElements.Add(new FileListElement { FileName = content.Name, Path = content.Path }); } else { ErrorLabel.Text = "This type cannot be uploaded!"; ErrorPlaceHolder.Visible = true; } }