我有以下文件结构,如下图
我的项目名称是myIGNOU
,文件夹内所有这些文件中的类类App_Code
都写在myIGNOU
namespace
.
但是有些事情真的让我很恼火,我可以从AppSettings.cs
file in Code2.cs
file 访问类,但不能从AppSettings.cs
in访问同一个类Code1.cs
。我尝试只是交换文件名,Code1.cs
但Code2.cs
没有运气,仍然是相同的行为。我也尝试在同一个文件夹中添加另一个类(在单独的文件中),但我仍然无法访问AppSettings.cs
这个新创建的类中的任何文件类。
为什么没有按钮来展开任何其他文件,但只是Code1.cs
当我在每个文件中有一些类(都是公共的)时..?
我错过了什么..?我也尝试过重命名App_Code
文件夹,但还是没有运气。
虽然Code1.cs
可以在其余类中访问所有文件类。
我认为这三个文件中的任何一个都没有被编译,因为如果我输入任何错误,就像lasdk;adj.j
我不会得到任何编译时错误一样。但我Compilation Error
在运行时得到。对于不在此文件夹中的其他文件(例如Default.aspx.cs
. 为此,我会在编译时出错。
这是代码
应用设置.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace myIGNOU
{
public static class AppSettings
{
//public static string ConnectionString { get { return "Data Source = .; Initial Catalog = SMR; Integrated Security = True;"; } }
//public static string ConnectionString2 { get { return "Data Source = .; Initial Catalog = shashwat; Integrated Security = True;"; } }
public static string ConnectionString { get { return "Data Source=IDCSQL2.znetlive.com,1234;Initial Catalog=smrbobdn;User Id=shashwat;Password=xxxx;"; } }
public static string ConnectionString2 { get { return "Data Source=IDCSQL2.znetlive.com,1234;Initial Catalog=shashwat;User Id=shashwat;Password=xxxx;"; } }
public static string ConStr1 { get { return "Data Source=.; Initial Catalog=myIGNOU; Integrated Security=true;"; } }
public static DateTime Now { get { return DateTime.Now.AddMinutes(0); } }
}
}
代码1.cs
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.IO;
using System.Net;
namespace myIGNOU
{
public class Student
{
public Student(string enrollmentNumber)
{
EN = enrollmentNumber;
}
public bool LoadFromDB()
{
bool ret = false;
SqlCommand com = new SqlCommand("SELECT * FROM StudentInfo WHERE EN = @en", new SqlConnection());
return ret;
}
public string EN { get; set; }
public string Name { get; private set; }
public string FatherName { get; private set; }
public string Program { get; private set; }
public string Address { get; private set; }
public string Mobile { get; set; }
public string Email { get; set; }
public uint RC { get; private set; }
public uint SC { get; private set; }
public uint AdmissionYear { get; private set; }
public uint AdmissionValid { get; private set; }
public uint UpdatedOn { get; private set; }
}
public class HttpRequest
{
string GetPageAsString(string path, string method, string dataToPost)
{
return "...";
}
}
public class Program
{
}
public class Semester
{
}
public class Course
{
}
}
代码2.cs
using System.Data.SqlClient;
using System.Text.RegularExpressions;
using System.Net.Mail;
namespace myIGNOU
{
public class CustomHttpRequest
{
}
public class Emails
{
public static MailAddressCollection GetAllEmails()
{
MailAddressCollection cc = new MailAddressCollection();
SqlCommand com = new SqlCommand("SELECT Email from myignou", new SqlConnection(AppSettings.ConnectionString));
com.Connection.Open();
SqlDataReader dr = com.ExecuteReader();
while (dr.Read())
{
cc.Add(dr[0].ToString());
}
com.Connection.Close();
return cc;
}
}
public class RegexUtilities
{
public static bool IsValidEmail(string strIn)
{
// Return true if strIn is in valid e-mail format.
return Regex.IsMatch(strIn,
@"^(?("")(""[^""]+?""@)|(([0-9a-zA-Z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-zA-Z])@))" +
@"(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,6}))$");
}
}
}