How to bind AspxMenu by .xml file value - asp.net

XElement xml = new XElement("contacts",
from c in db.Categories
orderby c.CategoryID
select new XElement("contact",
new XAttribute("contactId", c.CategoryID),
new XElement("firstName", c.CategoryName),
new XElement("lastName", c.Description))
);
// Saving to a file, you can also save to streams
xml.Save(#"C:\contacts.xml");
<dxm:ASPxMenu ID="ASPxMenu1" runat="server">
</dxm:ASPxMenu>
Using the above syntax i can save table value in XML format.But i can not bind this value to AspxMenubellow syntax show error.
ASPxMenu1.DataSource = xml;
ASPxMenu1.DataBind();
I try to save datavalue in xml format in specific location ,Then want to bind AspxMenu with this file value value.
After run the code C drive contain file named contacts.xml . I want to bind menu by this file.**Help me to bind.**HOw to bind AspxMenu by .xml file value

We have explained how to bind an ASPxMenu to an XMLDataSource in the following video:
http://tv.devexpress.com/#ASPxMenuBindXMLDataSource.movie
I hope, it will be helpful to you. In short, you should not only set the ASPxMenu's DataSourceID property, but also map item's Text, Image, Url, Name properties to the corresponding attributes in an xml node. This can be done by setting the ASPxMenu.TextField, ASPxMenu.ImageUrlField, ASPxMenu.NavigateUrlField and ASPxMenu.NameField properties. You can also read about these properties in our documentation available at:
http://documentation.devexpress.com

Related

How to dynamically load image into picturebox in fast report?

I have a table in Sql that has 2 columns containing header and address of images that related to that header like below:
Header address
194003 ~/viewerImages/1903-01-1-5-0-6-00143.jpg
194003 ~/viewerImages/1903-01-1-5-0-6-00161.jpg
194003 ~/viewerImages/1903-01-1-5-0-6-00190.jpg
194012 ~/viewerImages/1903-01-1-5-0-6-00143.jpg
194012 ~/viewerImages/1903-01-1-5-0-7-00141.jpg
194012 ~/viewerImages/1903-01-1-5-0-7-00160.jpg
194015 ~/viewerImages/1903-01-1-5-0-7-00180.jpg
194015 ~/viewerImages/1903-01-1-5-0-8-00159.jpg
194015 ~/viewerImages/1903-01-1-5-0-8-00184.jpg
I want to load these images dynamically in fastreport for each header.
what should I do?
One solution is to create an objet with some properties that are the images to load (image1, image2, image3). You also add more properties with the data that you want to print in the report.
Then, you can load the information in the object dinamically and after send the object to the report, so Fast Reports will print the information you are loading in the object. In this way you can do wharever you want dinamically.
For image properties, you can use Image or byte[] type.
To create the report:
var report = new Report();
report.Load(Constants.Paths.ReportFolder + "Return.frx");
report.RegisterData(myObject, "Name");
report.Design(); // if you want to open the designer before to print
report.Show();
Note: The object to register must be a collection of objects. In this case myObject would be a List. If you want to register a single object, you can do it in this way:
report.RegisterData(new List{ myObject }), "Name");
In the designer you can access all the properties.

How can i extract XML and use it as a datasource?

I am using asp.net VB and I have an XML file containing a set of data, I would like to use it in something like a datalist and where usually you would use a database i would like to use the XML file to produce the information.
Does anyone know how to do this, i have read about transform files but surely i will format the information in the control?
The file has multiple records so in some cases i would need to perform queries on the information through the datasource.
I would maybe look into XML serialization and de-serialization. Using de-serialization you could read your XML into a List(T) object containing a list of your own class objects and use that as a data source for your application.
Heres a link that you may find useful:
http://msdn.microsoft.com/en-us/library/ms731073.aspx
Hope this helps.
Dim ds As New DataSet()
ds.ReadXml(MapPath("data.xml"))
First you have to parse the XML and store that into custom C# object or you can directly pass the XML to your stored procedure and do the codding there for saving it into DB.
Passing the xml to stored procedure and manipulating it there is bit difficult so what I suggest is to parse it in C# and then get a custom object. Once you get it you can do whatever you want to.
Below is the sample code that parse a XML file and generate a custom C# object from it.
public CatSubCatList GenerateCategoryListFromProductFeedXML()
{
string path = System.Web.HttpContext.Current.Server.MapPath(_xmlFilePath);
XDocument xDoc = XDocument.Load(path);
XElement xElement = XElement.Parse(xDoc.ToString());
List<Category> lstCategory = xElement.Elements("Product").Select(d => new Category
{
Code = Convert.ToString(d.Element("CategoryCode").Value),
CategoryPath = d.Element("CategoryPath").Value,
Name = GetCateOrSubCategory(d.Element("CategoryPath").Value, 0), // Category
SubCategoryName = GetCateOrSubCategory(d.Element("CategoryPath").Value, 1) // Sub Category
}).GroupBy(x => new { x.Code, x.SubCategoryName }).Select(x => x.First()).ToList();
CatSubCatList catSubCatList = GetFinalCategoryListFromXML(lstCategory);
return catSubCatList;
}

How to get Tridion item ID after created using Core Service

I am creating a new item using the Core Service in this post. However, the URI of the newly created item is tcm:0-0-0 instead of the actual TCM URI. the Title property is correct (and not New Component) but the WebDav path returns 'New Component' while .
What is the best way to get the URI of my newly created item?
client.Create(newComponent, null);
string newItemUri = newComponent.Id; // returns tcm:0-0-0
string webDavUrl = newComponent.LocationInfo.WebDavUrl; // returns New%20Component
string title = newComponent.Title; // correct
Second parameter of Create method are ReadOptions. They are used to specify how the item will be read back. In your example you have it set to null, meaning you will not read it back. What you should do is set ReadOptions and assign item read back to a variable, like this:
newComponent = (ComponentData) client.Create(newComponent, new ReadOptions());
Check out Ryan's code at http://blog.building-blocks.com/uploading-images-using-the-core-service-in-sdl-tridion-2011. He uses client.Save to get the saved Component, from which he's able to access the ID.

dynamically generate ComboBox name

I have a script that parses some complex XML. When the XML element is of a certain type, it generates a comboBox using the XML element's children to populate the box. I then want to check all of the values of the all the generated ComboBoxes against their correct answers (which is also info stored in the XML file). When creating the ComboBoxes, I added an "id" property. However, it seems that I cannot them use:
dynamicQuestion.id.selectedItem.labelField
to check the answers. However, I am able to get the labelField if I know the variable name used to create the ComboBox.
dynamicQuestion.selectedItem.labelField
This indicates (to me) that I need to dynamically generate the variable name as I'm creating new instances of the ComboBox. But how do I dynamically generate a variable name? If I use
var thisBox:String = "box"+boxCount;
var newBox:ComboBox = thisBox as ComboBox;
I get an implicit coercion error. I also tried changing the creation statement to a function that accepted an argument, "thisBox," but this didn't work either. Conceptually, this seems quite simple, but I'm having a hard time putting it to practice. It seems that the comboBox's id is what is generated by created the box using script (e.g., var thisBox). How do I dynamically generate this name?
Use an array as Stefan suggested. If you must use string identifiers, you can create an object and use it as an associative array.
var combos:Object = {};
var boxCount:Number = 1;
var thisBox:String = "box"+boxCount;
//you can store comboboxes in the object using the following syntax
combos[thisBox] = new ComboBox();
//or
combos.box2 = new ComboBox();
//or
combos["box3"] = new ComboBox();
trace(combos.box1.selectedItem.labelField);
trace(combos.box2.selectedItem.labelField);
trace(combos.box3.selectedItem.labelField);
Why don't you store all your dynamically created combo boxes in an array? When you want to evaluate them you iterate over the array and access selectedItem.labelField.

How to specify the namespace when referencing a table in a dataset

I'm loading data into a DataSet from an XML file using the ReadXml method. This results in two tables with the same name. One of the tables has a namespace and the other doesn't. I'm trying to reference the table with the namespace. Can anyone tell me how to do this?
Dim reader As XmlTextReader = New XmlTextReader(strURL)
Dim city as string = ""
Dim ds As DataSet = New DataSet()
ds.Namespace = "HomeAddress"
ds.ReadXml(reader)
city = ds.Tables("Address").Rows(0).Item(2).ToString()
From MSDN: DataSet.Namespace
The Namespace property is used when
reading and writing an XML document
into the DataSet using the ReadXml,
WriteXml, ReadXmlSchema, or
WriteXmlSchema methods.
The namespace of an XML document is
used to scope XML attributes and
elements when read into a DataSet. For
example, if a DataSet contains a
schema that was read from a document
with the namespace "myCompany," and an
attempt is made to read data only from
a document with a different namespace,
any data that does not correspond to
the existing schema is ignored.
The following example sets the Prefix
before calling the ReadXml method.
private void ReadData(DataSet thisDataSet)
{
thisDataSet.Namespace = "CorporationA";
thisDataSet.Prefix = "DivisionA";
// Read schema and data.
string fileName = "CorporationA_Schema.xml";
thisDataSet.ReadXmlSchema(fileName);
fileName = "DivisionA_Report.xml";
thisDataSet.ReadXml(fileName);
}
I cant see from the example you gave, but unless you set your prefix before you load, you wont be able to read data that doesn't correspond to the existing schema.
I found the answer. You can pass in the namespace as the second parameter. I guess I didn't notice this particular overload in Intellisense.
ds.Tables("Address", "HomeAddress").Rows(1).Item(2).ToString()

Resources