I have a need to deploy ASP.NET application page from assembly to /Lists/ (http://server/Lists) folder.
How can I get "physical" page object
from page that is made in assembly?
Project tree http://img17.imageshack.us/img17/4242/ss20090922150130.png
How can I deploy this page as module
or by FeatureReceiver? "Physycally" folder Lists does not exist.
Thank you for assistance.
Edit: I want to do exactly what SharePoint Designer is doing by clicking this button:
SharePoint Designer http://img121.imageshack.us/img121/5163/ss20090923160323.png
I'm not sure exactly what you are after, but I'm guessing that you want to create a page and check it in to a list?
This code snippet does that for a publishing page in MOSS:
using (SPWeb web = siteCollection.RootWeb)
{
PublishingSite publishingSite = new PublishingSite(siteCollection);
PublishingWeb publishingWeb = PublishingWeb.GetPublishingWeb(web);
// Article Page content type
SPContentTypeId articleContentTypeID = new SPContentTypeId("0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF3900242457EFB8B24247815D688C526CD44D");
PageLayout[] layouts = publishingWeb.GetAvailablePageLayouts(articleContentTypeID);
PageLayout articlePageLayout = layouts[0];
string pageName = "LegalInformation.aspx";
SPQuery query = new SPQuery();
query.Query = string.Format("" +
"<Where>" +
"<Eq>" +
"<FieldRef Name='FileLeafRef' />" +
"<Value Type='File'>{0}</Value>" +
"</Eq>" +
"</Where>" +
"", pageName);
// Does the file already exists ?
PublishingPageCollection pageColl = publishingWeb.GetPublishingPages(query);
if (pageColl.Count > 0)
{
return;
}
PublishingPage newPage = publishingWeb.GetPublishingPages().Add(pageName, articlePageLayout);
newPage.ListItem[FieldId.Title] = "This page title";
newPage.ListItem[FieldId.PublishingPageContent] = "<P style='MARGIN-TOP: 20px'>Your content here</P>"";
newPage.Update();
// Check in file
if (newPage.ListItem.File.CheckOutStatus != SPFile.SPCheckOutStatus.None)
{
newPage.ListItem.File.CheckIn(string.Empty);
}
// Publish file
newPage.ListItem.File.Publish(string.Empty);
}
Related
How do I add a Forms widget inside another widget? I tried using FormZone() within the widget but nothing shows up.
It is not possible to render a Forms widget inside another widget in Kentico 12 MVC.
You will need to upgrade to Kentico Xperience 13 for this functionality - see https://docs.xperience.io/developing-websites/page-builder-development/rendering-widgets-in-code#Renderingwidgetsincode-Renderingwidgets
Technically, you can render a Form inside a Widget in Kentico 12, however it is not officially supported and requires a bit of custom development.
The key is to use IFormProvider and IFormComponentVisibilityEvaluator to get all the Form info so that you can render it manually (in a Controller):
var formInfo = BizFormInfoProvider
.GetBizFormInfo(formName, SiteContext.CurrentSiteName);
string className = DataClassInfoProvider
.GetClassName(formInfo.FormClassID);
var existingBizFormItem = className is null
? null
: BizFormItemProvider
.GetItems(className)?.GetExistingItemForContact(
formInfo, contactContext.ContactGuid);
var formComponents = formProvider
.GetFormComponents(formInfo)
.GetDisplayedComponents(
ContactManagementContext.CurrentContact,
formInfo, existingBizFormItem, visibilityEvaluator);
var settings = new JsonSerializerSettings
{
ContractResolver = new CamelCasePropertyNamesContractResolver(),
TypeNameHandling = TypeNameHandling.Auto,
StringEscapeHandling = StringEscapeHandling.EscapeHtml
};
var formConfiguration = JsonConvert.DeserializeObject<FormBuilderConfiguration>(
formInfo.FormBuilderLayout, settings);
var prefix = Guid.NewGuid().ToString();
ViewData.TemplateInfo.HtmlFieldPrefix = prefix;
return new FormWidgetViewModel
{
DisplayValidationErrors = true,
FormComponents = formComponents.ToList(),
FormConfiguration = formConfiguration,
FormName = formName,
FormPrefix = prefix,
IsFormSubmittable = true,
SiteForms = new List<SelectListItem>(),
SubmitButtonImage = formInfo.FormSubmitButtonImage,
SubmitButtonText = string.IsNullOrEmpty(formInfo.FormSubmitButtonText)
? ResHelper.GetString("general.submit")
: ResHelper.LocalizeString(formInfo.FormSubmitButtonText)
};
Then you would render the Form Model as an HTML Form using Kentico's Form rendering APIs:
<!-- ~/Views/Form/Form.cshtml -->
#using Kentico.Forms.Web.Mvc;
#using Kentico.Forms.Web.Mvc.Widgets;
#using Kentico.Forms.Web.Mvc.Widgets.Internal
#model FormWidgetViewModel
#{
var config = FormWidgetRenderingConfiguration.Default;
// #Html.Kentico().FormSubmitButton(Model) requires
// this ViewData value to be populated. Normally it
// executes as part of the Widget rendering, but since
// we aren't rendering a Widget, we have to do it manually
ViewData.AddFormWidgetRenderingConfiguration(config);
}
#using (Html.Kentico().BeginForm(Model))
{
#Html.Kentico().FormFields(Model)
#Html.Kentico().FormSubmitButton(Model)
}
You can read about the full configuration and setup in my blog post Kentico EMS: MVC Widget Experiments Part 3 - Rendering Form Builder Forms Without Widgets
I have been on a CRM 2011 project that uses a lot of custom views.
I recently figured it out that all lookup custom views are only working properly in the internet explorer. When I try using google chrome (Version 51.0.2704.84 m) it simple does not work.
I googled without luck.
Is anyone aware about how to solve that issue?
I'm sure many of you have faced the same problem.
Here is my code. I emphasize that it works like a charm in IE.
var viewId = "{1DFB2B35-B07C-44D1-868D-258DEEAB88E1}";
var entityName = "tz_tipodefrete";
var viewDisplayName = "Tipos de Frete Disponíveis";
var fetchXml =
"<fetch distinct='false' mapping='logical' output-format='xml-platform' version='1.0'>" +
"<entity name='tz_tipodefrete'>" +
"<attribute name='tz_name'/>" +
"<order descending='false' attribute='tz_ordem'/>" +
"<filter type='and'>";
if (filtrar)
fetchXml = fetchXml + "<condition attribute='tz_name' value='Cliente Retira e instala no CT' operator='ne'/>";
fetchXml = fetchXml +
"<condition attribute='statecode' value='0' operator='eq'/>" +
"</filter>" +
"</entity>" +
"</fetch>";
// build Grid Layout
var layoutXml = "<grid name='resultset' object='1' jump='tz_name' select='1' icon='1' preview='1'>" +
"<row name='result' id='tz_tipodefreteid'>" +
"<cell name='tz_name' width='600' />" +
"</row>" +
"</grid>";
Xrm.Page.getControl("tz_tipodefrete").addCustomView(viewId, entityName, viewDisplayName, fetchXml, layoutXml, true);
//Desabilita a opção do usuário trocar de view. Provável que pare de funcionar na migração para versão 2015
document.getElementById("tz_tipodefrete").setAttribute("disableViewPicker", "1");
Have you tried taking the brackets off the guid?
Ex. var viewId = "1DFB2B35-B07C-44D1-868D-258DEEAB88E1";
In some situations, that helps.
I want to delete the the Page with custom button. I have searched the the whole but found nothing. I have tried to find the ID of Delete button from Ribbon. But this also does not work.
I found a link but it does not help me.
[1] :https://sharepoint.stackexchange.com/questions/19887/custom-delete-page-button
Anyone here know about the solution.
I am surprised that no one have answer the question. Then I go deeper in Sharepoint and find a Solution to delete the page with custom Button or link.
So i decided to share with you guys. May be someone in future need this. I have achieve this through Javascript.
function deletePage() {
var url = document.location.pathname;
var urls = url.split("/");
var newurl = urls[1].concat("/", urls[2], "/", urls[3], "/Pages/Forms/AllItems.aspx");
var context = SP.ClientContext.get_current();
var web = context.get_web();
var folder = web.getFolderByServerRelativeUrl(url);
var confirmDelete = confirm("Do you want to delete this news ??");
if (confirmDelete) {
folder.deleteObject();
}
//if (confirmDelete) {
// window.location = "/" + newurl;
//}
context.executeQueryAsync(
function () {
if (confirmDelete) {
window.location = "/" + newurl;
}
}
);
}
And Just call this function onclick.
<li><i class="fa fa-close"></i>Delete</li>
Well this is working perfect.
Thanks
I need to set the page title (Page Title) of a SharePoint page in code. I have already tested
this.Page.Title = "My Page Title";
But this does not change the title when the page loads. Can anyone offer any advise on how to do this?
Thanks, MagicAndi
This blog post by Michael Becker gives a method of modifying the SharePoint Page title using the code below:
ContentPlaceHolder contentPlaceHolder = (ContentPlaceHolder) Page.Master.FindControl("PlaceHolderPageTitle");
contentPlaceHolder.Controls.Clear();
LiteralControl literalControl = new LiteralControl();
literalControl.Text = "My Page Title";
contentPlaceHolder.Controls.Add(literalControl);
If you want to change the page title from a webpart on the page for example, you could use this:
private void ChangeTitle(string newTitle)
{
SPListItem item = SPContext.Current.ListItem;
if (item != null)
{
item[SPBuiltInFieldId.Title] = newTitle;
item.SystemUpdate(false);
}
}
This will only work for a page in the pages library, because the default.aspx page in the root of your site doesn't have an associated listitem. Also don't forget to refresh your page after changing the title.
The SystemUpdate makes sure that 'modified/modified by' information is not updated and that the version number doesn't increase. If you want this information updated, replace it by item.Update();
I need to add a custom menu action to a custom content type programmatically in c#. This is because I will not know the URL I need to link to beforehand. The URL to link to will be pulled from configuration when the feature is activated.
I have tried the following:
Added the CustomAction in my Element.xml file as:
<CustomAction
Id="MyID"
RegistrationType="ContentType"
RegistrationId="0x010100ef19b15f43e64355b39431399657766e"
Location="EditControlBlock"
Sequence="1000"
Title="My Menu Item">
<UrlAction Url="" />
</CustomAction>
In my feature receiver FeatureActivated method, I have:
SPElementDefinitionCollection eleCollection =
properties.Feature.Definition.GetElementDefinitions(
new System.Globalization.CultureInfo(1));
foreach (SPElementDefinition ele in eleCollection)
{
if (ele.Id == "MyID")
{
System.Xml.XmlNode node = ele.XmlDefinition.FirstChild;
node.Attributes[0].Value = "MY URL";
ele.FeatureDefinition.Update(true);
}
}
I would expect this code to update the UrlAction Url with "MY URL" but it does not. If I hard code a URL in the XML it works but I must be able to do it programmatically.
You can use the SPUserCustomActionCollection on the SPWeb object:
using (SPSite site = new SPSite("http://moss.dev.com"))
using (SPWeb web = site.OpenWeb())
{
SPContentType contentType = web.ContentTypes["Curriculum Vitae"];
SPUserCustomAction action = web.UserCustomActions.Add();
action.RegistrationType = SPUserCustomActionRegistrationType.ContentType;
action.RegistrationId = contentType.Id.ToString();
action.Location = "EditControlBlock";
action.Sequence = 450;
action.Title = "Test";
action.Rights = SPBasePermissions.EditListItems;
action.Url = "http://www.google.com";
action.Update();
}
This way, you can set the URL to whatever you want. If you are updating an existing custom action, you can iterate through the collection and update the one you are looking for. Updating the element XML definition after you've installed the custom action doesn't do anything.
Depending on what you want to achieve, you can use some javascript;
<UrlAction Url="JavaScript:window.location='{SiteUrl}/_layouts/CustomListAction.aspx?ID={ListId}'"/>
the ~site and ~siteCollection also works:
<UrlAction Url="~site/_layouts/Page.aspx?ID={ListId}"/>
I don't think the WSS schema definition allows for an empty Url attribute in the UrlAction element. Maybe try putting a "default" url in the xml that you overwrite later?