When using SPWeb.GetCatalog(SPListTemplateType.WebPartCatalog), it returns an SPList which of course contains a SPListItemCollection of the web parts in the web part gallery.
When looping through the items, is there any easy way to get properties of the web parts? Such as AllowClose, CatalogIconImageUrl, etc...
I know I can probably accomplish this using the listItem.OpenBinaryStream etc and loading the xml of the .webpart file, but I wondered if there was an easier way to do this.
Nope. If you load the webparts like that all you get are SPListItems (which are from the gallery) and not SPWebPart objects (which you'll realistically only get from instances that exist on a page - or from loading in via an SPWebPartManager object [and even then loading from the gallery, you would need to extract the XML in exactly the same way anyway]). You'll have to do SPListItem.File.OpenBinaryStream() and fire it into an XmlReader or XDocument object for easier parsing.
Related
I'm an Umbraco newbie and trying to get up to speed. One of the things i'm trying out is the API and accessing a node in the content tree. Unfortunately documentation is a bit thin and i can't find any info covering such a basic task...
I've got a simple content structure
Content > Home > About
How do i retrieve the About node using C# and the API from a plain old model class?
In other CMS's it would be as simple as calling Database.GetItem("/content/home/about")
How is this achieved with Umbraco v5?
Thanks
If you have a single, specific piece of content you want to get it, you can select it using the hiveid like so:
Umbraco.GetContentById("content://p__nhibernate/v__guid/0000000000000000")
You can find your content id by examining the content's properties from the backoffice.
EDIT:
If you truly must get the content by uri, you could do so by querying the hive. I can't recommend it for performance though.
_context.Application.Hive.QueryContent().Where(x => x.NiceUrl().Equals("/faq/functionality/submit-a-question",StringComparison.InvariantCultureIgnoreCase);
What I need to do is quite simple although is causing me lots of trouble.
I need to create programmatically an AssetUrlSelector in a web part that selects a file in sharepoint 2010 and makes its path available to be used elsewhere.
So far I have managed to create the AssetUrlSelector and display the path on a textbox, however I cannot use this as every reference to it will be null.
Have you got any practical example?
Try the Document ID Service. In short this service generates IDs for documents (files) and generates an url with this ID so even if the file is moved the url stays valid and the service returns the document. This service might rely on search functionality unless you implement your custom search. Here is an article on how to configure OOB Doc IDs here. Also you can google further if you're interested.
My objective is to test the web page to verify that all of the inner text on the web page contains a special character at the beginning. Example: ( "*Refresh") is a label on the page.
I am using Visual Studio (2010) UI Automation Testing to create and run this test.
I can create an Assert for every innertext/element on the page, but that will be very time consuming. I wanted to know of another way that is faster and more efficient way to iterate through all of the innertexts on the web page to create this test.
You could load the document in an XML reader (supposing the page conforms to XML standards,
which it should), and then look at the nodes programatically.
To use xml classes, see other StackOverflow questions, like:
XDocument or XmlDocument
I want to write the entire contents of my application page (eg Mainpage.xml) to a file (in Isolated Storage ) How do I do it in WP7 ? are there any methods available to parse the page contents and write it to file in windows phone 7 ?
There is no built in way to do this.
However there are a couple of approaches you could try:
If the structure is static you could try and extract the resource containing this from the DLL. For future re-use it would be easier to load the page from the DLL again though.
If you're generating a page (or part of a page) at runtime (based on user input/preferences) and you want to be able to save/reload this then just save enough information to be able to recreate it. It's unlikely that XAML would be the best format for this though.
You could create this as you build the UI. Alternatively you could walk the visual tree to get details of all that is rendered. I'd recommend recording as you go so you can more easily keep track of non-default values in the rendered objects.
I know there is a lot of documentation on the internet as far as XSD to forms, but I have not been able to come across one that is straight forward enough for my situation.
I am working with a WCF web service that is going to fetch and .xsd xml schema, and must return the HTML of a form based on the .xsd xml schema. Is there any third party tools that can help out with this, if so what are they? If not, do you have any suggestions,better methods,etc for how this can be done?
I am working on my own project called XsdFormEditor. Application will be able to show any XSD as a form in WinForms (95% done), Web (using Asp.Net MVC, 0% done), WPF (0% done). Idea is to load any XSD file, show it to user as a form, let user input some data and save data as XML. User will be also able to load default values to form from XML file. You can find it here: https://github.com/janstafa/XsdFormEditor
Xsd is difficult to parse, but you can easily obtain a class from it, by calling xsd.exe /class or by doing it runtime following this beautiful sample:
http://mikehadlow.blogspot.com/2007/01/writing-your-own-xsdexe.html
hence with the classes representing your xsd you can use reflection to create the html code.
First of all, they will need not only to pass you the XSD (with no include, import or redefine elements in it), but will also need to tell you the root node.
Second, I would approach this by reading in the XSD with the XmlSchema.Read method. You could then loop through the object model pulling the information you need.
You might even try writing out an XML document containing the parts of the schema that you really need, and then running an XML Transform against it to produce the HTML.
Also, consider the Microsoft Office InfoPath product from Microsoft. Even if you don't wind up using the product itself, get a trial version to see how forms can be defined based on XSD plus other metadata.