Posts Tagged ‘ SharePoint ’

SPWebApplication Url


I was trying to get the url of a SharePoint web application, but I couldn’t find a Url property for that class. Trying out several properties, I finally found an easy way to get the Url:

string webUrl = webApp.GetResponseUri(SPUrlZone.Default).AbsoluteUri;

where webApp is a reference to an object of type SPWebApplication. For example, here is a sample code that displays all web urls in the Farm (except for Central Admin WebApp).

foreach (SPWebApplication webApp in SPWebService.ContentService.WebApplications)
{
    string webUrl = webApp.GetResponseUri(SPUrlZone.Default).AbsoluteUri;
    Console.WriteLine(webUrl);
}

SharePoint CAML IntelliSense


So you’ve been having some pain trying to put IntelliSense into your frequent CAML (Collaborative Application Markup Language) files. For every new XML file you create, you have to go to its properties and then point to the target schema located at ../TEMPLATE/XML/wss.xsd.

If you don’t know what I mean, usually, in order to display IntelliSense in an XML file opened through Visual Studio, we must link the XML file to an XSD. This is done by going to the file properties and linking to the XSD every time we open the XML file in Visual Studio.

One way to avoid having to link to the XSD every time, is to add the file(s) to a Visual Studio project. However, what if you create CAML files so frequently that you don’t want to add them to a Visual Studio project every time?

The best solution would be to load the XSD whenever a new XML file referencing it is opened; and I have the steps to do that!

Under the Schemas folder of the Visual Studio installation folder (Ex: C:\Program Files\Microsoft Visual Studio 9.0\Xml\Schemas), there is a file named Catalog.xml.

Reference wss.xsd from it by adding the following tag:

Make sure that href is pointing to the correct location of the wss.xsd file.

<Schema href="C:/Program Files/Common Files/Microsoft Shared/Web Server Extensions/12/TEMPLATE/XML/wss.xsd" targetNamespace="http://schemas.microsoft.com/sharepoint/" />

Enjoy!

Ali B

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: