I'm trying to use LINQ to XML to write queries for a WebDAV server but I'm having a problem where LINQ is setting a default namespace (xmlns = "bla") which doesn't seem to be supported by WebDAV.
XNamespace ns = "d";
var content = new XElement(ns + "propfind"
,new XAttribute(XNamespace.Xmlns + "d", "DAV:")
,new XElement(ns + "allprops"));
The expected output is:
<d:propfind xmlns:d="DAV:"><d:allprop /></d:propfind>
But no matter how I attempt to serialize (even with XElement.Save(someStream, SaveOptions.DisableFormatting)) I always get this which is not supported by the WebDav server I'm trying to hit.
<propfind xmlns:d="DAV:" xmlns="d"><allprop /></propfind>

The problem is that your element isn't in the DAV: namespace - it's in the d namespace. You need to differentiate between the namespace URI and the namespace alias. You want:
XNamespace ns = "DAV:";
var content = new XElement(ns + "propfind",
new XAttribute(XNamespace.Xmlns + "d", ns),
new XElement(ns + "allprops"));
See more on this question at Stackoverflow