|
|
Browse by Tags
All Tags » Useful Code Sni... » LINQ to XML (RSS)
-
[Blog Map] Web services are one of the most effective and convenient ways for casual developers to access SharePoint lists and document libraries. They have a reputation for being a bit difficult; LINQ to XML can make them easier to use. This post presents the basic steps for getting started with Windows SharePoint Services Web Services using LINQ to XML (either C# or VB). In several upcoming posts, I’ll present some more information about using web services, as well as more notes on the code presented Read More...
|
-
Sometimes you want to convert an XmlNode to an XElement and back again. Some programming libraries define methods that take XmlNode objects as parameters. These libraries also may contain properties and methods that return XmlNode objects. However, it is more convenient to work with LINQ to XML instead of the classes in System.Xml (XmlDocument, XmlNode, etc.) This post presents a bit of code to do these conversions. As an example of where you need these methods, you can do a lot with SharePoint using Read More...
|
-
When working with Open XML documents from within SharePoint, you may want to open a specific document, modify it in some way, and then save it, either replacing the original document, or saving to a new location. This isn’t very hard, but there are a few issues. This post describes the issues and presents a minimal amount of code that shows how to open an Open XML document from a SharePoint list, modify it, and then save it back to either the same location, or a different one if you desire. In detail, Read More...
|
-
[Blog Map] Excel has a very cool feature where you can declare that a range of cells is a table. It is a feature that allows you to use Excel very much like a database. You can add new rows as necessary, sort the table by columns, do some simple filtering, calculate the sum of columns, and more. Each table has a unique table name, and each column has a name unique to its table. Because these tables are stored in Open XML documents, we can implement some simple extension methods and some classes so Read More...
|
-
[Blog Map] A convenient way to explore Open XML markup is to create a small document, modify the document slightly in the Word user interface, save it, and then compare it with the Open XML Diff utility that comes with the Open XML SDK V2 . However, Word adds extraneous elements and attributes that enable merging of two documents that have forked. These elements and attributes show up as changed, and obscure the differences that we’re looking for. An easy way to deal with this is to remove these Read More...
|
-
Data-bound content controls are a powerful and convenient way to separate the semantic business data from the markup of an Open XML document. After binding content controls to custom XML, you can query the document for the business data by looking in the custom XML part rather than examining the markup. Querying custom XML is much simpler than querying the document body. However, it’s a little bit involved to create data-bound content controls (but only a little bit). But there is a trick we can Read More...
|
-
You may optionally be making a number of modifications to a very large XDocument object. Because of a complicated algorithm, you may not necessarily know ahead of time whether you will be making changes. If you don’t make any changes, then you don’t want to unnecessarily serialize the tree and save it to disk, or send it over the wire. This post presents a simple technique to determine if an XDocument has ever been modified since deserialization or creation. For example, you might have a very large Read More...
|
-
LINQ is a great tool for writing ad-hoc queries and transforms, and occasionally I need to write queries or transforms on text files. And sometimes I receive CSV files, and need to do something with them. I wrote a blog post on LINQ to Text files over two years ago. My coding practices today differ from what I presented in that blog post. This post presents my current approach for dealing with text files using LINQ, and includes a function for splitting CSV lines. In that post, I detailed an approach Read More...
|
-
Content controls are an effective way to add structure to word processing documents. You can write a very small LINQ query to retrieve the contents of content controls. This topic in Office Online provides more information on content controls. In an upcoming post, I’m going to show how you can write a small test harness to test code that is embedded in documents. This is particularly useful, say, to a program manager who has written a specification that contains a lot of code that shows how to use Read More...
|
-
You can use lambda expressions to write an event handler, even for classes that predate C# 3.0 and the latest version of the framework. This can shorten your code, and make it easier to read. For example, the code to validate an XML tree using an XSD schema takes an event handler because it may return multiple errors or warnings for a single validation pass. An easy way to write this code is as follows: using System; using System.Linq; using System.Collections.Generic; using System.IO; using System.Xml; Read More...
|
|
|
|