我创建了一个类文件,为我正在开发的一个用C#编写的网站生成日历事件。在本地,我可以添加类using myNamespace
,并且没有明显的错误告诉我找不到类型或命名空间。将鼠标悬停在代码中的类名上,它显示了正确的定义。
然而,当我将文件上传到web服务器时,我会收到错误:The type or namespace name 'vCalendar' could not be found (are you missing a using directive or an assembly reference?)
在visual studio中,我可以将鼠标悬停在下面的vCalendar
上:
vCalendar myAppointment = new vCalendar("TCHR", "www.website.com");
悬停在第一个上会给我一个class myNamespace.vCalendar
的消息,而悬停在第二个上则会给我vCalendar.vCalendar(string identifier, string netAddress)
的消息。
我的vCalendar类看起来像:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace myNamespace
{
public class vCalendar
{
private string identifier;
private string netaddress;
// Constructor:
public vCalendar(string identifier, string netaddress)
{
this.identifier = identifier;
this.netaddress = netaddress;
}
public string CreateAppointment(string uid, string organizer, DateTime startMeeting, DateTime endMeeting, string location, string summary, string description, int priority, int sequence)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.AppendLine("BEGIN:VCALENDAR");
sb.AppendLine("PRODID:-// " + identifier + "//" + netaddress + "//EN");
sb.AppendLine("VERSION:2.0");
sb.AppendLine("METHOD:REQUEST");
sb.AppendLine("BEGIN:VEVENT");
sb.AppendLine("UID:" + uid);
sb.AppendLine("SEQUENCE:" + sequence.ToString());
sb.AppendLine("ORGANIZER:" + organizer);
sb.AppendLine("DTSTART:" + ConvertToISO8601DateTime(startMeeting));
sb.AppendLine("DTEND:" + ConvertToISO8601DateTime(endMeeting));
sb.AppendLine("DTSTAMP:" + ConvertToISO8601DateTime(DateTime.Now));
sb.AppendLine("LOCATION:" + location);
sb.AppendLine("SUMMARY:" + summary);
sb.AppendLine("DESCRIPTION;ENCODING=QUOTED-PRINTABLE:" + description);
sb.AppendLine("TRANSP:OPAQUE");
sb.AppendLine("ACTION:DISPLAY");
sb.AppendLine("PRIORITY:" + priority.ToString());
sb.AppendLine("CLASS:PUBLIC");
sb.AppendLine("END:VEVENT");
sb.AppendLine("END:VCALENDAR");
return sb.ToString();
}
public string UpdateAppointment(string uid, string organizer, DateTime startMeeting, DateTime endMeeting, string location, string summary, string description, int priority, int sequence)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.AppendLine("BEGIN:VCALENDAR");
sb.AppendLine("PRODID:-// " + identifier + "//" + netaddress + "//EN");
sb.AppendLine("VERSION:2.0");
sb.AppendLine("METHOD:REQUEST");
sb.AppendLine("BEGIN:VEVENT");
sb.AppendLine("UID:" + uid);
sb.AppendLine("SEQUENCE:" + sequence.ToString());
sb.AppendLine("ORGANIZER:" + organizer);
sb.AppendLine("DTSTART:" + ConvertToISO8601DateTime(startMeeting));
sb.AppendLine("DTEND:" + ConvertToISO8601DateTime(endMeeting));
sb.AppendLine("DTSTAMP:" + ConvertToISO8601DateTime(DateTime.Now));
sb.AppendLine("LOCATION:" + location);
sb.AppendLine("SUMMARY:" + summary);
sb.AppendLine("DESCRIPTION;ENCODING=QUOTED-PRINTABLE:" + description);
sb.AppendLine("TRANSP:OPAQUE");
sb.AppendLine("ACTION:DISPLAY");
sb.AppendLine("PRIORITY:" + priority.ToString());
sb.AppendLine("CLASS:PUBLIC");
sb.AppendLine("END:VEVENT");
sb.AppendLine("END:VCALENDAR");
return sb.ToString();
}
public string CancelAppointment(string uid, string organizer, DateTime startMeeting, DateTime endMeeting, string location, string summary, string description, int priority, int sequence)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.AppendLine("BEGIN:VCALENDAR");
sb.AppendLine("PRODID:-// " + identifier + "//" + netaddress + "//EN");
sb.AppendLine("VERSION:2.0");
sb.AppendLine("METHOD:CANCEL");
sb.AppendLine("BEGIN:VEVENT");
sb.AppendLine("UID:" + uid);
sb.AppendLine("SEQUENCE:" + sequence.ToString());
sb.AppendLine("ORGANIZER:" + organizer);
sb.AppendLine("DTSTART:" + ConvertToISO8601DateTime(startMeeting));
sb.AppendLine("DTEND:" + ConvertToISO8601DateTime(endMeeting));
sb.AppendLine("DTSTAMP:" + ConvertToISO8601DateTime(DateTime.Now));
sb.AppendLine("LOCATION:" + location);
sb.AppendLine("SUMMARY:" + summary);
sb.AppendLine("DESCRIPTION;ENCODING=QUOTED-PRINTABLE:" + description);
sb.AppendLine("TRANSP:OPAQUE");
sb.AppendLine("ACTION:DISPLAY");
sb.AppendLine("PRIORITY:" + priority.ToString());
sb.AppendLine("CLASS:PUBLIC");
sb.AppendLine("END:VEVENT");
sb.AppendLine("END:VCALENDAR");
return sb.ToString();
}
private static string ConvertToISO8601DateTime(DateTime dt)
{
string _dt = string.Format("{0:yyyyMMddTHHmmss}", dt); // ISO 8601
return _dt;
}
}
}
我真的不确定我做错了什么。我已将所有文件上传到网上。我在班级档案里做错什么了吗?我是否需要以using
命令以外的其他方式包含此内容?
要从网站使用C#class
,您需要将项目编译为DLL,然后将DLL复制到web服务器,以便您的web代码可以使用它。