You can encounter a problem that
<%# ResHelper.GetString(key) %> does not work.
Please use this format:
<%= ResHelper.GetString(key) %>
-hg-
This issue may occur after upgrade to version 5.0.
There should be following code in version 5.0 in ~\CMSInlineControls\ImageControl.ascx.cs (round the line 480):
imgParams.Url = GetFileIconUrl(this.Extension, "List");
However in version 4.x it looks like this:
imgParams.Url = ImageHelper.GetFileIconUrl(this.Extension, "List");
So it's possible that this line has been overwritten during import process of 4.1 web site into 5.0 version.
If you use the smart search you may use the
Eval function in transformation:
<%# Eval("Pages") %>.
If you use the SQL search you may
clone the
SearchResult web part and add the code like this:
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
if (srchResults.DataSource != null)
ltlRepeaterCount.Text = srchResults.DataSource.Tables[0].Rows.Count.ToString();
}
It needs to add the literal control with
ltlRepeaterCount ID to the template.
Please check if you use '%' character in your path for representation of sub-tree. If so, please remove it and specify full alias path of document instead. This macro is no longer supported by this method as it can be used in name of document (you can still use it in SelectNodes method though).
You can use sample code bellow:
using CMS.SiteProvider;
...
// Tree node
CMS.TreeEngine.TreeNode node = null;
// Tree provider
UserInfo ui = UserInfoProvider.GetUserInfo("administrator");
CMS.TreeEngine.TreeProvider tree = new CMS.TreeEngine.TreeProvider(ui);
// Get Single node specified by it`s ID
node = tree.SelectSingleNode(nodeId);
//Get GUID of attachment
Guid existingGuid = ValidationHelper.GetGuid(node.GetValue("FileAttachment"), Guid.Empty);
if (existingGuid != Guid.Empty)
{
// Get the attachment
AttachmentInfo existingAttachment =
am.GetAttachmentInfo(existingGuid, CMSContext.CurrentSite.SiteName);
}
You can use sample code bellow:
CMS.TreeEngine.TreeNode node = treeNodeObj as CMS.TreeEngine.TreeNode;
int documentCheckedOutVersionHistoryID = node.DocumentCheckedOutVersionHistoryID;
CMS.WorkflowEngine.VersionHistoryInfo whi = CMS.WorkflowEngine.VersionHistoryInfoProvider.GetVersionHistoryInfo(documentCheckedOutVersionHistoryID);
string comment = whi.VersionComment;
You may use the overloaded method with OrderBy parameter (see
API Reference for more details) but it sorts documents only within one document type. If you use more document types (classes) please use standard ASP.NET methods to sort the dataset. Please see the
MSDN documentation for more information.
Regrettably, SQL search doesn't support this functionality. You may use the Smart search feature (it is the new feature since 4.1 version) that natively support this functionality instead. Please see
Smart search chapter in Developer’s Guide for more details.
If you are using
extension-less ULRs for your web site, by default any postback adds an .aspxextension to the URL. You can disable this behavior using following key in your web.config file:
<add key="CMSUseExtensionOnPostback" value="false"/>
You can also use following sample code to get data (DataSet) from custom table:
CMS.SiteProvider.CustomTableItemProvider tp = new
CMS.SiteProvider.CustomTableItemProvider(CMS.CMSHelper.CMSContext.CurrentUser);
DataSet ds = tp.GetItems("CustomTableCodeName", "whereCondition", "OrderBy");
The 'dataObj' object can be both of DataClass and SimpleDataClass class in according to circumstances. Could you please check the class first and then re-type the object to appropriate class? Please see example at
http://msdn.microsoft.com/en-us/library/scekt9xw.aspx
This is caused by this setting doesn't affect directly the data of document. You can use OnAfterInsert method of CustomDataHandler instead (there comes SimpleDataClass object in dataObj parameter and it contains ClassName equal to 'ACLItem').
For this purpose you can use following expression within your transformation:
<%# (CMS.CMSHelper.CMSContext.CurrentPageInfo.DocumentName.ToString() == Eval("MenuItemName").ToString() ? "curent page" : "not current") %>
It compares current document name with the value in the MenuItemName field. If they are equal the text after "?" sign is returned else you receive the text after ":". Please note it's only example, so you can adjust it to suit your needs.
You can use following sample expression in WhereCondition parameter of SelectNodes or SelectDocuments method to get documents from category specified by its ID:
"DocumentID IN (SELECT DocumentID FROM CMS_DocumentCategory WHERE CategoryID = " + categoryId.ToString() + ")"
This issue is caused by UserCustomData is default column in CMS_User table (it's similar to CustomData field for document, please see '
Custom document data' section of DevGuide for more details) and is not related to custom field added to User system table anyhow (this field is added into CMS_User table as separate column). Please use following sample code instead:
userInfo.SetValue("NameOfField", value);
You can use sample code bellow to find out value of field (in this case called 'Name') of document currently processed by repeater and show/hide the custom user control accordingly (in this case show it if name is 'Kentico' and hide it otherwise):
<script runat="server">
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
if (this.Parent is IDataItemContainer)
{
IDataItemContainer cont = this.Parent as IDataItemContainer;
if (cont != null)
{
System.Data.DataRowView drv = (System.Data.DataRowView)cont.DataItem as System.Data.DataRowView;
if (drv != null)
{
this.myUserControl.Visible = (drv["Name"].ToString() == "Kentico");
}
else
{
Response.Write("Error: DataRowView is null");
}
}
else
{
Response.Write("Error: IDataItemContainer is null");
}
}
}
</script>
Please find sample code bellow:
EmailMessage msg = new CMS.EmailEngine.EmailMessage();
EmailTemplateInfo eti = EmailTemplateProvider.GetEmailTemplate("myTemplate", CMSContext.CurrentSiteID);
MacroResolver mcr = new MacroResolver();
mcr.SpecialMacros = new String[,] {{"#macro#", "text"}} ; //here you can specify text for multiple macros specified in template
msg.EmailFormat = EmailFormatEnum.Both;
msg.From = eti.TemplateFrom;
msg.Recipients = "name@domain.com";
msg.Subject = eti.TemplateSubject;
EmailSender.SendEmailWithTemplateText(CMSContext.CurrentSiteName, msg, eti, mcr, true );
You can use sample code bellow:
// Converts IP4 address to country name.
CMS.WebAnalytics.IP2CountryHelper ip2country = new CMS.WebAnalytics.IP2CountryHelper();
string country = ip2country.GetCountryByIp("<IP>");
There may be some problem processing the last WebAnalytics log. Try to remove the oldest file off the ~\App_Data\CMSModules\WebAnalytics\ folder. This sometimes happens, but it will be fixed in 4.1 version. Some files aren't processed due to incorrect file names. Could you please also check if the scheduler runs correctly? Please go to Site Manager -> Administration -> Scheduled tasks, and try to manually run the "Analytics log processing" task.
Since version 4.0 it's possible to refer to images with any extension in URL. You need to go through following procedure:
1) Please set 404 error handler as described in
extension less URL settings
2) You may need to set e.g.
.gif extension for your image (document) in:
CMS Desk -> Content -> Document -> Properties tab -> URLs -> Url extensions.
3) And then you need to set
'Document URL path' property. [
/some_folder for example]
You may develop your own control which uses standard ASP.NET validators. But when you insert the control on the page it fires the validation of your control’s fields if any button is pressed on the same page (for example the Search button in the Search box web part).
In this case, you would need to add this property to all buttons on the same page:
CausesValidation="false"
For example the declaration of Search button may look like:
<asp:Button CausesValidation="false" ID="btnGo" runat="server" OnClick="btnGo_Click" EnableViewState="false" />
If you want to add custom functionality for example after deleting a document type from the application you cannot use CustomDataHandler events for this purpose. You can register your custom event handler in ~/App_Code/Global/CMS/CMSApplication.cs file in AfterApplicationStart method using following sample code:
CMS.SettingsProvider.DataClassInfo.TYPEINFO.OnAfterDelete += new CMS.SettingsProvider.TypeInfo.ObjectActionEventHandler(TYPEINFO_OnAfterDelete);
void TYPEINFO_OnAfterDelete(CMS.SettingsProvider.IInfoObject infoObj)
{
throw new NotImplementedException();
}
Kentico CMS adds following code into master page when using Portal engine approach:
<link rel="shortcut icon" href="/<VirtualDirectoryName>/favicon.ico" />
If you want for some reason to use your custom path to your favicon or simply not want this link to be generated in your web pages, you can simply delete file "favicon.ico" from root of your web project folder and add your custom link to your favicon in CMS Desk -> Content -> click root -> Master Page tab section. Please note that this operation requires application restart.
Please open "Site Manager -> Development -> Web parts -> unfold Listing and viewers -> Image gallery -> Properties -> Thumbnail transformation" section, check the "" check box and click 'ok' to save changes. Then you should be able to edit 'Thumbnail transformation' in properties of Image gallery web part and modify it as you need.
You need to call ReloadData method of repeater after setting its properties in code-behind. You can also set 'DataBindByDefault' property of repeater (on aspx template) to false so the repeater won't bind data by default and will bind them only after you call ReloadData method.
You can use following sample code in Kentico CMS 4.0:
CMS.SiteProvider.UserInfo ui = CMS.SiteProvider.UserInfoProvider.AuthenticateUser(txtboxUsername.Text, txtboxPassword.Text, CMS.CMSHelper.CMSContext.CurrentSite.SiteName);
if (ui != null)
{
System.Web.Security.FormsAuthentication.SetAuthCookie(ui.UserName, true);
CMS.CMSHelper.CMSContext.SetCurrentUser(new CMS.CMSHelper.CurrentUserInfo(ui, true));
CMS.SiteProvider.UserInfoProvider.SetPreferredCultures(ui);
}
You can use following sample code:
<img src="<%# GetDocumentUrl("fieldName", "") %>" />
You can use following function to find out if page with given full url exists in the site (it returns null if page doesn't exist):
CMS.PortalEngine.PageInfoProvider.GetPageInfoForUrl(...);
We are aware of this issue and want to deal with it in some of next versions. We are sorry for your inconveniences.
However, you may set the control properties in the Source mode of Visual studio - it is not restricting the functionality.
Please check if there is a
CMSPageManager control on your master page (.master). For more details please see:
devnet.kentico.com/docs/devguide/using_the_master_pages.htm.
If the same error persists please check also the
ScriptManager -
<asp:ScriptManager ID="manScript" runat="server" /> - some of our controls need it.
If you leave blank fields(which shouldn’t be empty according to document type definition) during the creation of new document, check it in and save it document will be stored with the empty field which is not correct in this case. The error saying you can’t save a null value to the database then occurs when you try to publish the document.
To solve this issue please open ~\CMSDesk\Content\edit.aspx file and put content of following methods: btnCheckIn_Click, btnReject_Click, btnApprove_Click into following condition:
// Validate the form first
if (formElem.BasicForm.ValidateData())
{
...
}
The inserted node is not available at that moment because the transaction on the SQL server is still running at the moment when the event fires.
You can try to ensure this in the following file which contains the code for creating new documents from the administration interface:
~\CMSDesk\Content\edit.aspx.cs