An error occurred while naming ASP. NET Web controls

Source: Internet
Author: User

EngageProgramEveryone knows that the naming of variables should not conflict with the language keywords. Today, I also encountered a problem caused by the naming of ASP. NET Web controls. This problem is easy to confuse people.

I created a page named "file. aspx" andCodeThe "file" class is used on the page. According to the general operation, first import the "system. io "namespace, the results in the Code body found that the file class does not have its common method, even if you manually write a correct File class operation code, it cannot be compiled, the method added after the file class is not included in the file class. The error code is as follows:


Using System;
Using System. Data;
Using System. configuration;
Using System. collections;
Using System. Web;
Using System. Web. Security;
Using System. Web. UI;
Using System. Web. UI. webcontrols;
Using System. Web. UI. webcontrols. webparts;
Using System. Web. UI. htmlcontrols;
Using System. IO;

Public   Partial   Class File: system. Web. UI. Page
{
Protected   Void Page_load ( Object Sender, eventargs E)
{
Streamreader SR = File. opentext (server. mappath ( " . " ) + " \ Table. SQL " );
}
}

You may have noticed the problem, that is, there are two file classes, one is system. io. file, the other is to automatically generate a class public partial class file with the same name as the file name when creating a web page. In this case, the file class definition in the Code body streamreader sr = file is ambiguous, in this case, the IDE automatically prompts that the member is under the public partial class file class, so the problem occurs at the beginning.

Knowing where the problem is, the solution will naturally be found. One solution is to always remind you not to duplicate the name of the created web page file with the class to be used in the Code. Another more scientific method is to use the namespace full name or namespace alias, as shown below:


Using System;
Using System. Data;
Using System. configuration;
Using System. collections;
Using System. Web;
Using System. Web. Security;
Using System. Web. UI;
Using System. Web. UI. webcontrols;
Using System. Web. UI. webcontrols. webparts;
Using System. Web. UI. htmlcontrols;
Using System. IO;

Public   Partial   Class File: system. Web. UI. Page
{
Protected   Void Page_load ( Object Sender, eventargs E)
{
Streamreader SR = System. Io. file. opentext (server. mappath ( " . " ) + " \ Table. SQL " );
}
}

This problem is obviously simple, but a little careless will make you think that there is a problem with the. NET Framework or vs IDE, it is worth noting!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.