Prabir's Blog

where the tech matters...

Custom web.config Intellisense

May 27
by prabir 27. May 2009 01:28

(This is a part of my series Visual Studio Tips and Tricks – III )

Intellisense ExampleThere are at times when you would like to have intellisense support for you custom providers like the ones Microsoft provides.

In this post, I will be guiding you on the way how to create a basic intellisense for your BlogEngine.NET provider model for web.config.

You can open your BlogEngine.NET sourcecode or any of your websites to try it. But in this tutorial I will be sticking with BlogEngine.NET source code.

  1. To make stuffs clean I like to put all my Intellisense files (XSD schemas) in a folder called schemas. Please go ahead and create the folder. Add a new image item to your schemas folder. You can name it anything. Out here for simplicity I will name it blogengine.xsd.
  2. Change the target namespace to something meaning full. I prefer to have it like http://schemas.[company name]/product/year/month but its your choice. For now lets stick to http://schemas.prabir.me/blogengine/2009/5.
  3. Lets first have a look at our web.config file, and try to understand the schema.
<BlogEngine>
    <blogProvider defaultProvider="XmlBlogProvider">
        <providers>
  <add name="XmlBlogProvider" type="BlogEngine.Core.Providers.XmlBlogProvider, BlogEngine.Core"/>
  <add name="DbBlogProvider" type="BlogEngine.Core.Providers.DbBlogProvider, BlogEngine.Core" connectionStringName="BlogEngine"/>
        </providers>
    </blogProvider>
</BlogEngine>
  1. I will not be teaching you how to write XSD schemas. There is a good article at W3schools out here where you can learn more. For now just paste the code to your xsd schema file you created earlier. (Just looking at my code you can already learn a lot about xsd schemas – I would recommend you to download the code files at the end of the article for better formatting and readability).
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="blogengine"
targetNamespace=
"http://schemas.prabir.me/blogengine/2009/5"
elementFormDefault="qualified"
xmlns="http://tempuri.org/blogengine.xsd"
xmlns:mstns="http://tempuri.org/blogengine.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
>
<xs:element name="BlogEngine">
<xs:complexType>
<xs:sequence>
<xs:element name="blogProvider" minOccurs="1">
<xs:complexType>
<xs:sequence>
<xs:element name="providers" minOccurs="1" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="add" minOccurs="1" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="name" type="xs:string" use="required" />
<xs:attribute name="type" type="xs:string" use="required" />

<xs:attribute name="connectionStringName" type="xs:string" use="optional" />

</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="defaultProvider" type="xs:string"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
  1. Finally to make your schema work, you will have to add the xmlns attribute to your web.config file which looks like below.
<BlogEngine xmlns="http://schemas.prabir.me/blogengine/2009/5">

custom_webconfig_intellisense.zip (3.65 kb) [Downloads: 83]


Share/Save/Bookmark Subscribe

Tags: ,

BlogEngine.NET | Visual Studio | Visual Studio Tips and Tricks

Comments

5/27/2009 2:01:29 AM #

trackback

Tips and Tricks

Tips and Tricks

Prabir's Blog

5/27/2009 2:02:50 AM #

trackback

Custom web.config Intellisense

You've been kicked (a good thing) - Trackback from DotNetKicks.com

DotNetKicks.com

5/27/2009 2:13:29 AM #

trackback

Prabir's Blog | Custom web.config Intellisense

Thank you for submitting this cool story - Trackback from DotNetShoutout

DotNetShoutout

5/29/2009 10:31:14 AM #

SEO-SEM Consultant

       I decided to create my new blog. I am busy searching what topic, what power content and what application i apply must have my new blog. In i observed that Joomla is very useful in many blog i see. Thanks for the information.

SEO-SEM Consultant United States

5/29/2009 11:32:16 AM #

torrent articles


I enjoy reading your topic and i will this site again if i have time again.,If I will have time because this days I am so busy .,to many work to be done

torrent articles United States

6/10/2009 1:19:58 AM #

Franchises for sale

It's interesting, the blog engine platform seems very variable in form.  My design skills are not so good as my C coding though, I would be interested in seeing what additional skins you can get for it.  Nice blog btw, best wishes for it and keep up the posts. Smile  Kind regards,  Peter sims.

Franchises for sale United States

6/10/2009 3:59:08 PM #

prabirshrestha

Thanks guys for cheering me up.

prabirshrestha Nepal

7/16/2009 10:53:51 AM #

entin

thank you for your tips

entin Indonesia

blog comments powered by Disqus