I need to add this namespace to my c# file:
using System.Data;
Is there a way to automatically add this to newly created pages in c#.net?
I don't want to add this namespace to new pages.
I need to add this namespace to my c# file:
using System.Data;
Is there a way to automatically add this to newly created pages in c#.net?
I don't want to add this namespace to new pages.
Open %Program Files%\Microsoft Visual Studio 8\Common7\IDE\ItemTemplates\CSharp\1033\Class.zip, Or: %Program Files%\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\CSharp\Code\1033
You can modify the class.cs file within that's used to generate all new C# source files - it looks like this:
using System;
using System.Collections.Generic;
using System.Text;
namespace $rootnamespace$
{
class $safeitemrootname$
{
}
}
Also, there is a file called Class.vstemplate. Open this and you can edit the following:
<Reference>
<Assembly>System</Assembly>
</Reference>
<Reference>
<Assembly>System.Data</Assembly>
</Reference>
<Reference>
<Assembly>System.Xml</Assembly>
</Reference>
</References>
You can create a custom template (see here) that contains the namespace delcaration, or you can edit the existing template if you need it always and for every project.
You can edit the default item templates to add whatever you want OR make your own. The default templates are here (or you get the gist of their location from my machine): C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ItemTemplates
Understand that (at least in prior versions of VS) there was a cache of templates as well, so you would have to edit the zipped template AND look for a directory with the same name as the zip file and edit the templates in there/delete the directory.
You can put it in the web.config file.
<pages>
<namespaces>
<add namespace="System" />
<add namespace="System.Collections" />
<add namespace="System.Collections.Specialized" />
<add namespace="System.Configuration" />
<add namespace="System.Text" />
<add namespace="System.Text.RegularExpressions" />
<add namespace="System.Web" />
<add namespace="System.Web.Caching" />
<add namespace="System.Web.SessionState" />
<add namespace="System.Web.Security" />
<add namespace="System.Web.Profile" />
<add namespace="System.Web.UI" />
<add namespace="System.Web.UI.WebControls" />
<add namespace="System.Web.UI.WebControls.WebParts" />
<add namespace="System.Web.UI.HtmlControls" />
</namespaces>
<!-- Other elements -->
</pages>
This can be used to add the namespace in all the pages