In ASP.NET 2.0, you can control which namespaces are
imported automatically by configuring them in web.config.
Any namespace you define in web.config will be automatically imported,
and you will not have to import it specifically.
See :
http://msdn2.microsoft.com/en-us/lib...ollection.aspx
and
http://msdn2.microsoft.com/en-us/lib...essection.aspx
re:
I hope the above 6 namespaces "do" get imported automatically by all ASP.NET pages.
If not, then please let me know.
BTW, are there any additional namespaces apart from the above 6 that
all ASP.NET pages import automatically?
In ASP.NET 2.0, the default namespaces are defined in the default web.config, located in :
Drive:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\ CONFIG
Here they are :
<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>
</pages>
You could add System.IO, so it's automatically imported, by adding :
<add namespace="System.IO" />
to the <namespacessection of web.config.
Of course, any other namespace you want to import automatically can also be added.
Juan T. Llibre, asp.net MVP
aspnetfaq.com :
http://www.aspnetfaq.com/
asp.net faq :
http://asp.net.do/faq/
foros de asp.net, en español :
http://asp.net.do/foros/
===================================
"Arpan" <ar******@hotmail.comwrote in message
news:11*********************@m79g2000cwm.googlegro ups.com...
Thanks Juan for pointing out my mistake. Actually the ASP.NET book I am
referring to learn ASP.NET states that System.IO is one of the seven
namespaces that get imported automatically by all ASP.NET pages - the
remaining 6 being
System
System.Collections
System.Web
System.Web.UI
System.Web.UI.HtmlControls
System.Web.UI.WebControls
I hope the above 6 namespaces "do" get imported automatically by all
ASP.NET pages. If not, then please let me know. God knows what all I
must have learnt wrong from that ASP.NET book!
BTW, are there any additional namespaces apart from the above 6 that
all ASP.NET pages import automatically?
Thanks once again,
Regards,
Arpan
Juan T. Llibre wrote:
re:
If I am not wrong, System.IO is one of the seven namespaces
that get imported in all ASP.NET page automatically
You are wrong.
If you wish to use System.IO, you must import it explicitly.
Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
"Arpan" <ar******@hotmail.comwrote in message
news:11**********************@m79g2000cwm.googlegr oups.com...
If I am not wrong, System.IO is one of the seven namespaces that get
imported in all ASP.NET page automatically but in the following code:
<%@ Import Namespace="System.IO" %>
<script runat="server">
Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs)
Dim ioFileInfo As New FileInfo("C:\Inetpub\wwwroot\File1.asp")
lblOutput.Text = "Name: " & ioFileInfo.Name & "<br>"
lblOutput.Text += "Path: " & ioFileInfo.DirectoryName & "<br>"
lblOutput.Text += Last Accessed: " & ioFileInfo.LastAccessTime
& "<br>"
lblOutput.Text += Last Written: " & ioFileInfo.LastWriteTime &
"<br>"
lblOutput.Text += Size: " & ioFileInfo.Length & " bytes"
End Sub
</script>
<form runat="server">
<asp:Label ID="lblOutput" runat="server">
</form>
if I get rid of the <%@ Import.....%line, then ASP.NET generates the
following error:
Type 'FileInfo' is not defined.
pointing to the very first line within the Page_Load sub (Dim
ioFileInfo As New FileInfo...).
Why?
Please correct me if I am wrong.
Thanks,
Arpan