programmatically create smartform ektron - c#

I have created the smartform and generated the relevant class using a bat file (using xsd to generate c# class). Then I assigned that created smartform to a particular folder and I created the sample smartforms using the CMS work area.
Is there a way to create a smartform from code behind? I have tried as follows, but it didn't work as expected:
ContentType<root> cData = new ContentType<root>();
cData.SmartForm.EventName = "Conference Event1";
cData.SmartForm.EventDescription = "Test Description";
cData.SmartForm.EventDate = DateTime.Now.AddMonths(2).ToString("yyyy-MM-dd");
ContentTypeManager<root> contentTypeManager = new ContentTypeManager<root>();
contentTypeManager.Add(cData);

I have found the solution. You can achieve it using ContentManager.
ContentManager contentManager = new ContentManager(ApiAccessMode.Admin);
Ektron.Cms.ContentData contentData = new Ektron.Cms.ContentData();
contentData.Title = "title 011";
contentData.Html = "<root><EventName>Change1...</EventName>" +
"<EventDescription>Description Test</EventDescription>" +
"<EventDate>2014-10-30</EventDate>" +
"</root>";
contentData.ContType = 1;
contentData.Comment = "Automatically generated from a script.";
contentData.FolderId = 86; //folder id to save you smart data
contentData.IsPublished = true;
contentData.IsSearchable = true;
contentData.LanguageId = 1033;
contentData.XmlInheritedFrom = 86; //folder id to save you smart data
Ektron.Cms.XmlConfigData xcd = new Ektron.Cms.XmlConfigData();
xcd.Id = 7; //SmartForm ID
contentData.XmlConfiguration = xcd;
contentManager.Add(contentData);

Related

How to add a first page footer different from default one in NPOI - Docx?

I'm generating a docx file using NPOI 2.5.2 and I stuck with headers/footers for first page.
I'd like to have a first page custom footer and start numbering pages from the second one.
Here is my code for the first page footer:
// First page
doc.Document.body.sectPr = new CT_SectPr();
var footer = new CT_Ftr();
var footerParagraph = footer.AddNewP();
footerParagraph.AddNewR().AddNewT().Value = $"FIRST PAGE CUSTOM FOOTER";
var footerPar = new XWPFParagraph(footerParagraph, doc);
var parsFooter = new XWPFParagraph[1];
parsFooter[0] = footerPar;
var headerFooterPolicy = doc.GetHeaderFooterPolicy();
if (headerFooterPolicy == null)
headerFooterPolicy = doc.CreateHeaderFooterPolicy();
headerFooterPolicy.CreateFooter(XWPFHeaderFooterPolicy.FIRST, parsFooter);
Here is my code for the default footer with page numbering:
// Other pages
footerParagraph = footer.AddNewP();
footerParagraph.AddNewR().AddNewFldChar().fldCharType = ST_FldCharType.begin;
footerParagraph.AddNewR().AddNewInstrText().Value = " PAGE ";
footerParagraph.AddNewR().AddNewFldChar().fldCharType = ST_FldCharType.separate;
footerParagraph.AddNewR().AddNewFldChar().fldCharType = ST_FldCharType.end;
footerPar = new XWPFParagraph(footerParagraph, doc);
parsFooter = new XWPFParagraph[1];
parsFooter[0] = footerPar;
headerFooterPolicy.CreateFooter(XWPFHeaderFooterPolicy.DEFAULT, parsFooter);
With the code above I could not see the first page custom footer but the page numbering in every page. What am I doing wrong?
I found this similar question but I could not find addNewTitlePg method in NPOI.
And is there any appropriate documentation with examples about NPOI?
Here is my code with the first footer working. (using NPOI 2.5.3)
var doc = new XWPFDocument();
using (var sw = File.Create("fileformat.docx"))
{
XWPFParagraph p1 = doc.CreateParagraph();
XWPFParagraph p2 = doc.CreateParagraph();
XWPFRun r1 = p1.CreateRun();
XWPFRun r2 = p2.CreateRun();
r1.SetText("The quick brown fox");
r1.AddBreak(BreakType.PAGE);
r2.SetText("Next page: The quick brown fox");
doc.Document.body.sectPr = new CT_SectPr();
var policy = doc.CreateHeaderFooterPolicy();
var ctSectPr = doc.Document.body.sectPr;
if (ctSectPr.titlePg == null)
{
ctSectPr.titlePg = new CT_OnOff() { val = true };
}
var firstFooter = policy.CreateFooter(ST_HdrFtr.first);
var paragraph = firstFooter.CreateParagraph();
var run = paragraph.CreateRun();
run.SetText("First page footer...");
var defaultFooter = policy.CreateFooter(ST_HdrFtr.#default);
paragraph = defaultFooter.CreateParagraph();
run = paragraph.CreateRun();
paragraph.Alignment = ParagraphAlignment.RIGHT;
paragraph.GetCTP().AddNewR().AddNewFldChar().fldCharType = ST_FldCharType.begin;
paragraph.GetCTP().AddNewR().AddNewInstrText().Value = " PAGE ";
paragraph.GetCTP().AddNewR().AddNewFldChar().fldCharType = ST_FldCharType.separate;
paragraph.GetCTP().AddNewR().AddNewFldChar().fldCharType = ST_FldCharType.end;
run = paragraph.CreateRun();
doc.Write(sw);
}

How to customize a tooltip for each individual datapoint in a wpf toolkit lineseries chart?

I have seen several questions about doing a custom tooltip for a single line series.
I need a custom tool-tip for each data-point. I would like to add more to the tool-tip than just the dependent value path and the independent value path.
Example I have 2 data points on the same line one with a value(Y-axis)
of 2, date(x-axis) of 4/28/2016, and configuration of A. The other has
a value of 3, date of 4/29/2016, and configuration of B.
How would I also show the configurations? This is all done in code behind because I have a dynamic number of lineseries. So I can't just assign a style to each lineseries in the xaml.
var MyLineSeries = new LineSeries();
lMyLineSeries.DependentValuePath = "Y";
lMyLineSeries.IndependentValuePath = "X";
lMyLineSeries.DataPointStyle = lToolTipDataPointStyle;
This is my code for creating the tool tip style.
var lToolTipDataPointStyle = new Style(typeof(LineDataPoint));
var lTemplate = new ControlTemplate(typeof(LineDataPoint));
var lGridElement = new FrameworkElementFactory(typeof(Border));
//Tooltip
var lStackPanel = new StackPanel();
var lValueContentControl = new ContentControl();
lValueContentControl.SetBinding(ContentControl.ContentProperty, new Binding(myLineSeries.DependentValuePath));
lValueContentControl.ContentStringFormat = "Value: {0}";
var lConfigurationContentControl = new ContentControl();
lConfigurationContentControl.SetBinding(ContentControl.ContentProperty, new Binding())//This is what Idk what to bind to???
lConfigurationContentControl.ContentStringFormat = "Configuration: {0}";
lStackPanel.Children.Add(lValueContentControl);
lStackPanel.Children.Add(lConfigurationContentControl);
lGridElement.SetValue(ToolTipService.ToolTipProperty, lStackPanel);
var lEllipseElement = new FrameworkElementFactory(typeof(Ellipse));
lEllipseElement.SetValue(Ellipse.StrokeThicknessProperty, new TemplateBindingExtension(Border.BorderThicknessProperty));
lEllipseElement.SetValue(Ellipse.StrokeProperty, new TemplateBindingExtension(Border.BorderBrushProperty));
lEllipseElement.SetValue(Ellipse.FillProperty, new TemplateBindingExtension(Grid.BackgroundProperty));
lGridElement.AppendChild(lEllipseElement);
lTemplate.VisualTree = lGridElement;
var lTemplateSetter = new Setter();
lTemplateSetter.Property = LineDataPoint.TemplateProperty;
lTemplateSetter.Value = lTemplate;
lToolTipDataPointStyle.Setters.Add(lTemplateSetter);
return lToolTipDataPointStyle;
I figured it out by using the Tag on the Line series.
myLineSeries.Tag = "Configuration";
var lConfigurationContentControl = new ContentControl();
lConfigurationContentControl.SetBinding(ContentControl.ContentProperty, new Binding(myLineSeries.Tag.ToString()))
lConfigurationContentControl.ContentStringFormat = "Configuration: {0}";

How to create notes using EWS Managed API 2.0

Even looking into MSDN's Exchange 2013 - 101 Code Samples, I could not find an example creating notes using EWS Managed API 2.0. On Folders and items in EWS in Exchange, the most appropriate item type seems to me PostItem but my test failed trying to create such items in Notes folder. Or, is it possible there is no API for creating notes in this library?
A PostItem isn't the same as a note in the Notes folder. PostItem's represent items with a message class of IPM.Post. Notes, on the other hand, use the message class IPM.StickyNote. The managed API has no direct support for these items. You can retrieve them as EmailMessage objects, and you can even create them as EmailMessage objects if you manually set the required properties. Glen has a good write-up on his blog: http://gsexdev.blogspot.com/2009/07/creating-sticky-notes-in-ews-managed.html
Take a look at the PostItem, they should do what you want. PostItem
Sample
var items = new List<PostItem>();
for (int i = 0; i != 10; ++i)
{
var m = new PostItem(service);
m.Subject = "Note " + i.ToString();
m.Body = new MessageBody(BodyType.Text, "A test note");
m.Save();
}
var guid = new Guid("0006200E-0000-0000-C000-000000000046");
var colour = new ExtendedPropertyDefinition(guid, 0x8B00, MapiPropertyType.Integer);
var width = new ExtendedPropertyDefinition(guid, 0x8B02, MapiPropertyType.Integer);
var height = new ExtendedPropertyDefinition(guid, 0x8B03, MapiPropertyType.Integer);
var left = new ExtendedPropertyDefinition(guid, 0x8B04, MapiPropertyType.Integer);
var top = new ExtendedPropertyDefinition(guid, 0x8B05, MapiPropertyType.Integer);
var items = new List<EmailMessage>();
for (int i = 0; i != maxItems; ++i)
{
var m = new EmailMessage(service);
m.Subject = "Note " + i.ToString();
m.ItemClass = "IPM.StickyNote";
m.Body = new MessageBody(BodyType.Text, "A test note");
m.SetExtendedProperty(colour, 1);
m.SetExtendedProperty(width, 200);
m.SetExtendedProperty(height, 166);
m.SetExtendedProperty(left, 200);
m.SetExtendedProperty(top, 200);
items.Add(m);
}
var folder = Folder.Bind(service, WellKnownFolderName.Notes, new PropertySet());
var responses = service.CreateItems(items, folder.Id, MessageDisposition.SaveOnly, SendInvitationsMode.SendToNone);

windows phone 8.1 bing maps clustering

Hello i am using windows map control described in this link and i have a MapLayer with multiple MapOverlays with differents pois on map. And i want to do the clustering thing. I try to do this but no ClusteringLayer exist and no Pushpin. How can i do the clustering?
var cluster = new ClusteringLayer();
layer = new ClusteringLayer(Mymap)
{
ClusterRadius = 10,
ClusterType = ClusteringType.Grid
};
//Add event handlers to create the pushpins
layer.CreateClusteredItemPushpin += CreateClusteredItemPushpin1;
layer.CreateItemPushpin+=layer_CreateItemPushpin;
private MapOverlay layer_CreateItemPushpin(object item, ClusteredPoint clusterInfo)
{
var x = clusterInfo.Location;
var poi = new BuildingPoi { Coordinate = x, Buid = _selectedBuild };
var imagePoiLocation = new Image
{
Source = new BitmapImage(new Uri("/Assets/MapPin.png", UriKind.Relative)),
DataContext = poi
};
var over = new MapOverlay();
imagePoiLocation.Tap += loadClickedBuilding;
over.Content = imagePoiLocation;
over.PositionOrigin = new Point(0.5, 0.5);
over.GeoCoordinate = new GeoCoordinate(x.Latitude, x.Longitude);
return over;
}
private MapOverlay CreateClusteredItemPushpin1(ClusteredPoint clusterInfo)
{
var x = clusterInfo.Location;
var poi = new BuildingPoi { Coordinate = x, Buid = _selectedBuild };
var imagePoiLocation = new Image
{
Source = new BitmapImage(new Uri("/Assets/MapPin.png", UriKind.Relative)),
DataContext = poi
};
var over = new MapOverlay();
imagePoiLocation.Tap += loadClickedBuilding;
over.Content = imagePoiLocation;
over.PositionOrigin = new Point(0.5, 0.5);
over.GeoCoordinate = new GeoCoordinate(x.Latitude, x.Longitude);
return over;
}
As they don't have any nuget package or dll to reference directly, you need to download the source code of specific classes like ClusteringLayer & PushPin with related .cs files or the project itself to your machine and add reference of this project in your windows phone project to get ClusteringLayer and PushPin classes.
See following screenshot for ClusteringLayer class. For other classes, just import the solution to visual studio and you will see source code of all the classes. BTW, ClusteringLayer constructor need at-least one argument in cluster.
I advice you to download source code and get familiar with it's usage from samples in source code.

Insert an image into a .docx file

I am developing a program that has the feature to dynamically create DocX files. As the title suggests, I am having a problem inserting images into a DocX file. One of the issues, as I see it, is that I am using C# 2.0. (When answering this question, I would like to stress that I do not wish to switch to C# 3.0, so please do not try to persuade me.)
I have taken a look at the MSDN article at http://msdn.microsoft.com/en-us/library/office/bb497430.aspx, but when I converted the C# 3.0 code that MSDN uses to C# 2.0, I get a document that does not open, and it gives me the error: "The file Testing.docx cannot be opened because there are problems with the contents," and "No error detail available."
Here is my code:
ImagePart ip_Part;
WordprocessingDocument wpd_Doc = WordprocessingDocument.Create("C:\\Convert\\Testing.docx", WordprocessingDocumentType.Document);
public Testing()
{
wpd_Doc.AddMainDocumentPart();
wpd_Doc.MainDocumentPart.Document = new Document();
wpd_Doc.MainDocumentPart.Document.Body = new Body();
ip_Part = wpd_Doc.MainDocumentPart.AddImagePart(ImagePartType.Png);
System.IO.FileStream fs_Stream = new System.IO.FileStream("image.png", System.IO.FileMode.Open);
ip_Part.FeedData(fs_Stream);
AddImageToBody("image.png", wpd_Doc.MainDocumentPart.GetIdOfPart(ip_Part));
AppendText("Here is a test bulleted list:");
wpd_Doc.MainDocumentPart.Document.Save();
//Close the document.
wpd_Doc.Close();
}
private void AddImageToBody(string s_ImagePath, string s_RelationshipId)
{
//OpenXmlElement oxe_Element = new Numbering();
Drawing d_Drawing = new Drawing();
DrawWord.Inline i_Inline = new DrawWord.Inline();
DrawWord.Extent e_Extent = new DrawWord.Extent();
e_Extent.Cx = 600075; //63px / 96dpi * 914400
e_Extent.Cy = 600075; //63px / 96dpi * 914400
i_Inline.Extent = e_Extent;
DrawWord.DocProperties dp_Prop = new DrawWord.DocProperties();
//dp_Prop.Id = uint.Parse(System.DateTime.Now.Minute.ToString() + System.DateTime.Now.Second.ToString() + System.DateTime.Now.Millisecond.ToString());
dp_Prop.Id = 1;
dp_Prop.Name = "Picture 1";
dp_Prop.Description = "An automated image.";
i_Inline.DocProperties = dp_Prop;
DrawWord.NonVisualGraphicFrameDrawingProperties nvgfdp_Prop = new DrawWord.NonVisualGraphicFrameDrawingProperties();
Draw.GraphicFrameLocks gfl_Locks = new Draw.GraphicFrameLocks();
gfl_Locks.NoChangeAspect = true;
nvgfdp_Prop.GraphicFrameLocks = gfl_Locks;
i_Inline.NonVisualGraphicFrameDrawingProperties = nvgfdp_Prop;
Draw.Graphic g_Graphic = new Draw.Graphic();
Draw.GraphicData gd_Data = new DocumentFormat.OpenXml.Drawing.GraphicData();
gd_Data.Uri = DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + DateTime.Now.Millisecond.ToString();
DrawPic.Picture p_Pic = new DrawPic.Picture();
DrawPic.NonVisualPictureProperties nvpp_Prop = new DrawPic.NonVisualPictureProperties();
DrawPic.NonVisualDrawingProperties nvdp_Prop = new DrawPic.NonVisualDrawingProperties();
nvdp_Prop.Id = uint.Parse(System.DateTime.Now.Minute.ToString() + System.DateTime.Now.Second.ToString() + System.DateTime.Now.Millisecond.ToString());
//nvdp_Prop.Name = s_ImagePath;
nvdp_Prop.Name = "New_Image.png";
nvpp_Prop.NonVisualDrawingProperties = nvdp_Prop;
DrawPic.NonVisualPictureDrawingProperties nvpdp_Prop = new DrawPic.NonVisualPictureDrawingProperties();
nvpp_Prop.NonVisualPictureDrawingProperties = nvpdp_Prop;
p_Pic.NonVisualPictureProperties = nvpp_Prop;
DrawPic.BlipFill bf_Fill = new DrawPic.BlipFill();
Draw.Blip b_Blip = new Draw.Blip();
Draw.ExtensionList el_List = new Draw.ExtensionList();
Draw.BlipExtension be_Extension = new Draw.BlipExtension();
be_Extension.Uri = "{28A0092B-C50C-407E-A947-70E740481C1C}";
el_List.Append(be_Extension);
b_Blip.Append(el_List);
b_Blip.Embed = s_RelationshipId;
b_Blip.CompressionState = Draw.BlipCompressionValues.Print;
bf_Fill.Blip = b_Blip;
Draw.Stretch s_Stretch = new Draw.Stretch();
Draw.FillRectangle fr_Rect = new Draw.FillRectangle();
s_Stretch.FillRectangle = fr_Rect;
bf_Fill.Append(s_Stretch);
p_Pic.BlipFill = bf_Fill;
DrawPic.ShapeProperties sp_Prop = new DrawPic.ShapeProperties();
Draw.Transform2D t2d_Transform = new Draw.Transform2D();
Draw.Offset o_Offset = new Draw.Offset();
o_Offset.X = 0;
o_Offset.Y = 0;
t2d_Transform.Offset = o_Offset;
Draw.Extents e_Extents = new Draw.Extents();
e_Extents.Cx = 600075; //63px / 96dpi * 914400
e_Extents.Cy = 600075; //63px / 96dpi * 914400
t2d_Transform.Extents = e_Extents;
sp_Prop.Transform2D = t2d_Transform;
Draw.PresetGeometry pg_Geom = new Draw.PresetGeometry();
Draw.AdjustValueList avl_List = new Draw.AdjustValueList();
pg_Geom.AdjustValueList = avl_List;
pg_Geom.Preset = Draw.ShapeTypeValues.Rectangle;
sp_Prop.Append(pg_Geom);
p_Pic.ShapeProperties = sp_Prop;
gd_Data.Append(p_Pic);
g_Graphic.GraphicData = gd_Data;
i_Inline.Graphic = g_Graphic;
d_Drawing.Inline = i_Inline;
//oxe_Element.Append(d_Drawing);
//Run r_Run = new Run(d_Drawing);
wpd_Doc.MainDocumentPart.Document.Body.AppendChild(new Paragraph(new Run(d_Drawing)));
}
(The variable names are bad, but this was just a test program, so I did not spend too much time. Also, I have the lines spaced to mimic the Xml format that MSDN had in its example. If I could use the C# 3.0 syntax, I would, but I am using Visual Studio 2005.)
I have found the answer. Surprisingly, I did not find this webpage--because it was some Google pages down with some odd keyword searching--that completely worked: http://blog.stuartwhiteford.com/?p=33. Though it is written with Collection Initializations, I was able to change them to fit C# 2.0 standards.

Categories

Resources