Create list using .stp template using CSOM - console-application

I want to create list using .stp file which is uploaded in to the list template Gallary.
--> I am using Console application to create list in online site.
--> have an any idea how to add list from stp file at online site.
I am not getting custom list using below code.
listTemplate = Context.Web.ListTemplates.First(t => t.ListTemplateTypeKind == TemplateID);
How should i get .stp list template in context ?

First is just a LINQ query to get the first item.
I assume you are using the Client-Side OM?
Did you have explicitely requested Context.Web.ListTemplates (as in: did you ClientContext.Load(ListTemplates)) ? Otherwise it will not be available.
Try this:
var site = context.Web;
context.Load(site,s => s.ListTemplates );
context.ExecuteQuery();
var listCreationInfo = new ListCreationInformation
{
Title = "<Your Title>",
Description = "<Your Description>"
};
var listTemplate = site.ListTemplates.First(lt => lt.Name == "<Your Template Name>");
listCreationInfo.TemplateFeatureId = listTemplate.FeatureId;
listCreationInfo.TemplateType = listTemplate.ListTemplateTypeKind;
site.Lists.Add(listCreationInfo);
context.ExecuteQuery();

Related

Sitecore SXA - Multi-Root TreeList - Data Source Query

Within our Sitecore SXA 1.9 project, we're having a Template with a Multi-Root Treelist field.
This field has the following query:
query:/sitecore/content/Event Sites//*[##name='Home']
As a result, the field is populated as:
Would it be possible to display the actual website names instead of '(Current Site)'?
If you are using this code (https://gist.github.com/kamsar/33d1245ffdb630b1f126) for multi root treelist, then you should be able by creating a custom MultiRootTreeView by extending MultiRootTreeView and use it instead of the default Sitecore.Web.UI.WebControls.MultiRootTreeview()
Create a custom tree view here (adjust according to your need btw)
using Sitecore.Data.Items;
using Sitecore.Diagnostics;
using Sitecore.Web.UI.WebControls;
namespace Sitecore.Foundation.SitecoreExtensions.FieldTypes
{
public class EnhancedMultiRootTreeview : MultiRootTreeview
{
protected override string GetHeaderValue(Item item)
{
Assert.ArgumentNotNull(item, "item");
var nodeTitle = string.IsNullOrEmpty(DisplayFieldName) ? item.DisplayName : item[DisplayFieldName];
return $"{nodeTitle} - <span>({item.Paths.ContentPath})</span>";
}
}
}
Use your Custom MultiRootTreeview here (within your MultiRootTreeList Implementation)
var impostor = new EnhancedMultiRootTreeview
{
ID = existingTreeView.ID,
DblClick = existingTreeView.DblClick,
Enabled = existingTreeView.Enabled,
DisplayFieldName = existingTreeView.DisplayFieldName
};

Signature disappears when inserting documents to template

I'm trying to insert a word document into a Docusign template. The document inserts properly, but in addition to the two signers set up in the code, one of the signers that was on the template stays. Also, the second signature field is removed. Is there a setting that I'm missing? Here's my code:
List<TemplateRole> roleslist = new List<TemplateRole>();
TemplateRole InternalSignerRole = new TemplateRole(); // Set the Template Roles for the Internal Signer
InternalSignerRole.Email = _currentDocInfo.sInternalSignerEmail;
InternalSignerRole.Name = _currentDocInfo.sInternalSignerName;
InternalSignerRole.RoleName = "SignerInternal";
roleslist.Add(InternalSignerRole); // add to Template Roles list
TemplateRole ExternalSignerRole = new TemplateRole(); // Set the Template Roles for the External Signer
ExternalSignerRole.Email = _currentDocInfo.sExternalSignerEmail; //Create Template Roles for ExternalSigner
ExternalSignerRole.Name = _currentDocInfo.sExternalSignerEmail;
ExternalSignerRole.RoleName = "SignerExternal";
roleslist.Add(ExternalSignerRole);
var apiClient = new ApiClient(conn.Base_URL);
DocuSign.eSign.Client.Configuration.Default.ApiClient = apiClient;
DocuSign.eSign.Client.Configuration.Default.AddDefaultHeader("X-DocuSign-Authentication", authHeader);
string accountId = null;
// login call is available in the authentication api
var authApi = new AuthenticationApi();
var loginInfo = authApi.Login();
// parse the first account ID that is returned (user might belong to multiple accounts)
accountId = loginInfo.LoginAccounts[0].AccountId;
var baseUrl = loginInfo.LoginAccounts[0].BaseUrl;
var separator = new string[] { "/restapi" };
var basePath = baseUrl.Split(separator, StringSplitOptions.None)[0] + "/restapi";
apiClient = new ApiClient(basePath);
EnvelopeDefinition envDef = new EnvelopeDefinition();
envDef.EmailSubject = emailSubject;
envDef.EmailBlurb = emailBody;
//add custom fields you sent over with the document
envDef.CustomFields = letterCustomFields;
// Add a document to the envelope
envDef.Documents = letterDocs;
// Add a recipient to sign the document
envDef.TemplateRoles = roleslist;
envDef.TemplateId = "478d85c2-dc7c-4a89-a985-7d7a9101e36a";
First off, please don't use legacy authentication. That is old, not as secure and should not be used in new code that you're building.
Note that tabs (signature elements) are associated with both a recipient (a specific one) as well as a document (a specific one).
If you are trying to replace a document in a template, when creating an envelope from it (which is what you're doing, you're not replacing the document in the template, but rather in the envelope you create), you need to ensure the tabs refer to the same document and same recipient (based on the role).
Also, another recommendation is to use composite templates, which provide more flexibility for such scenarios. See excellent blog post by Gil Vincent for more information.

SharePoint List CSR handler are not fired - SharePoint online

I am trying to change style of sharepoint list using CSR. I want to apply bold to title column. I have added these code in JS file and reffered as JSLink(JavaScriptDisplayTemplate) to webpart. On document ready both renderTitleHandler & preRenderHandler are registered and also preRenderHandler are called successfully. But renderTitleHandler are not fired.
Please find my code snippet,
function renderTitleHandler(ctx) {
var fieldVal = ctx.CurrentItem[ctx.CurrentFieldSchema.Name];
var title = fieldVal.toString();
var html = '';
html += '<b>' + title + '</b>';
return html;
}
function preRenderHandler(ctx) {
ctx.ListTitle = '<b>' + ctx.ListTitle + '</b>';
}
(function() {
var overrideCtx = {};
overrideCtx.Templates = {};
overrideCtx.Templates.OnPreRender = preRenderHandler;
overrideCtx.Templates.Fields = {
"Title" : {"View" : renderTitleHandler}
};
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCtx);
})();
Thanks in advance.
Kannan.
Possibilities:
disable Minimal Download Strategy (mds). Sometimes this blocks your
javascripts caused by the async loading in the back of certain OOTB
scripts
remove the debugger;-line (is it possible that your code works when developer tools in your browser are open?)
Edit:
Found an example on my dev environment and i have the word View between quotes:
linkFilenameFiledContext.Templates.Fields = {
"Title": { "View": renderTitleHandler}
};
Hope it helps

How to search for Items that doesn't contain certain keywords using Sitecore Advanced Database Crawler?

I have millions of items in the database. And user can search those items based on the keyword. In the search function, I need to provide a feature that search for NOT that keyword.
For example Item A has a field called msg and the value is Sitecore is awesome and great.
In the search box, user can check the checkbox that indicates to show any item that doesn't contain the keyword. Maybe user key in is keyword, so Item A will not be displayed or retrieved by ADC.
Edit: Currently I'm using sitecore6.6, thus Search method has been deprecated. I have tried the Not keyword by using Occurrence.MustNot, but it doesn't return any result.
The Sitecore Advanced Database Crawler is an extension of the Sitecore.Search API and Sitecore.Search API is a wrapper around Lucene.
In Lucene you can user queries with NOT or - to exclude something like "Sitecore NOT awesome" or "Sitecore -awesome".
To exclude something you need at least one include term.
Not sure if it works, but give it a try.
This is untested, but you might have luck by using a MatchAllDocsQuery and supplying the keywords in the form of a Filter.
BooleanQuery booleanQuery = new BooleanQuery();
QueryParser queryParser = new QueryParser("msg", new StandardAnalyzer());
Query userQuery = queryParser.Parse("Sitecore is awesome and great");
booleanQuery.Add(userQuery, reverseQuery.Checked ? BooleanClause.Occur.MUST_NOT : BooleanClause.Occur.MUST);
MatchAllDocsQuery matchAllQuery = new MatchAllDocsQuery();
Filter filter = new QueryFilter(booleanQuery);
using (QueryRunner queryRunner = new QueryRunner("myIndex"))
{
var skinnyItems = queryRunner.RunQuery(matchAllQuery, filter, ...)
}
What I have done to NOT include the keywords associated with the result item set is this:
protected List<Item> getSearchResults(string queryToSearch, string selectedFilter, string notToSearch)
{
Database db = Sitecore.Context.Database;
var index = SearchManager.GetIndex("siteSearchIndexName");
using (SortableIndexSearchContext context = new SortableIndexSearchContext(index))
{
if (!String.IsNullOrWhiteSpace(query))
{
query.ToLower();
CombinedQuery cq = new CombinedQuery();
QueryBase qbKeyword = new FieldQuery("_orderkeywordpair", query);
QueryBase qbContent = new FieldQuery("_content", query);
QueryBase qbHtml = new FieldQuery("html", query);
if (!String.IsNullOrWhiteSpace(selectedFilter) && selectedFilter.ToLower() != "all")
{
QueryBase qbFilter = new FieldQuery("_pagetype", selectedFilter);
cq.Add(qbFilter, QueryOccurance.Must);
}
cq.Add(qbKeyword, QueryOccurance.Should);
cq.Add(qbContent, QueryOccurance.Must);
cq.Add(qbHtml, QueryOccurance.MustNot);
SearchHits hits = context.Search(cq);

Deleting a file from sharepoint using web service

I am trying to delete a file from a sharepoint document library.
My application is in C#, which uses the web services of sharepoint.
Would like to know how this can be done.
Thanks in advance.
Delete a Document in SharePoint using Web Services
1.Add Web Reference to http://[your site]/_vti_bin/Lists.asmx
2.You need Document ID, Library Name, and Url to the document to be deleted
var spWebServiceLists = "http://[your site]/_vti_bin/Lists.asmx";
var listService = new Lists
{
Credentials = CredentialCache.DefaultCredentials,
Url = spWebServiceLists
};
string id = 10;
string library = #"Shared Documents";
string url = #"http://[your site]/Shared Documents/Test.docx";
string xml = "<Method ID='1' Cmd='Delete'>" +
"<Field Name='ID'>" + id + "</Field>" +
"<Field Name='FileRef'>" + HttpUtility.UrlDecode(url) + "</Field>" +
"</Method>";
/*Get Name attribute values (GUIDs) for list and view. */
System.Xml.XmlNode ndListView = listService.GetListAndView(library, "");
string strListID = ndListView.ChildNodes[0].Attributes["Name"].Value;
string strViewID = ndListView.ChildNodes[1].Attributes["Name"].Value;
/*Create an XmlDocument object and construct a Batch element and its
attributes. Note that an empty ViewName parameter causes the method to use the default view. */
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
System.Xml.XmlElement batchElement = doc.CreateElement("Batch");
batchElement.SetAttribute("OnError", "Continue");
batchElement.SetAttribute("ListVersion", "1");
batchElement.SetAttribute("ViewName", strViewID);
/*Specify methods for the batch post using CAML. To update or delete,
specify the ID of the item, and to update or add, specify
the value to place in the specified column.*/
batchElement.InnerXml = xml;
XmlNode item;
item = listService.UpdateListItems(library, batchElement);
I just tested this code and works well.
For more information please see following links
Lists.UpdateListItems Method
How to: Update List Items
If you work with SharePoint 2010, you can use CSOM to access SharePoint web services. This link could be helpful to execute crud operations. If you work with SharePoint 2013 there is also CSOM API, it has similar funcitonality as in 2010.