C# 初始化属性时出现问题

C# 初始化属性时出现问题,c#,asp.net,sharepoint,C#,Asp.net,Sharepoint,我不断地发现这个错误: CS0501:“jQueryUploadTest.Upload.FileStatus.thumbnail\u url.get”必须声明一个正文,因为它没有标记为抽象或外部 我在我的sharepoint项目之外的单独网站上有这段代码,它运行良好。每当我尝试在sharepoint项目中实现它时,我都会遇到这个错误 以下是我的upload.ashx文件的代码: <%@ WebHandler Language="C#" Class="jQueryUploadTest.Upl

我不断地发现这个错误: CS0501:“jQueryUploadTest.Upload.FileStatus.thumbnail\u url.get”必须声明一个正文,因为它没有标记为抽象或外部

我在我的sharepoint项目之外的单独网站上有这段代码,它运行良好。每当我尝试在sharepoint项目中实现它时,我都会遇到这个错误

以下是我的upload.ashx文件的代码:

<%@ WebHandler Language="C#" Class="jQueryUploadTest.Upload" %>

using System;
using System.Collections.Generic;
using System.IO;
using System.Security.AccessControl;
using System.Web;
using System.Web.Script.Serialization;

namespace jQueryUploadTest {

    public class Upload : IHttpHandler {
        public class FilesStatus
        {
            public string thumbnail_url { get; set; }
            public string name { get; set; }
            public string url { get; set; }
            public int size { get; set; }
            public string type { get; set; }
            public string delete_url { get; set; }
            public string delete_type { get; set; }
            public string error { get; set; }
            public string progress { get; set; }
        }
        private readonly JavaScriptSerializer js = new JavaScriptSerializer();
        private string ingestPath;
        public bool IsReusable { get { return false; } }
        public void ProcessRequest (HttpContext context) {
            //var r = context.Response;
            ingestPath = @"C:\temp\ingest\";

            context.Response.AddHeader("Pragma", "no-cache");
            context.Response.AddHeader("Cache-Control", "private, no-cache");

            HandleMethod(context);
        }

        private void HandleMethod (HttpContext context) {
            switch (context.Request.HttpMethod) {
                case "HEAD":
                case "GET":
                    ServeFile(context);
                    break;

                case "POST":
                    UploadFile(context);
                    break;

                case "DELETE":
                    DeleteFile(context);
                    break;

                default:
                    context.Response.ClearHeaders();
                    context.Response.StatusCode = 405;
                    break;
            }
        }

        private void DeleteFile (HttpContext context) {
            string filePath = ingestPath + context.Request["f"];
            if (File.Exists(filePath)) {
                File.Delete(filePath);
            }
        }

        private void UploadFile (HttpContext context) {
            List<FilesStatus> statuses = new List<FilesStatus>();
            System.Collections.Specialized.NameValueCollection headers = context.Request.Headers;

            if (string.IsNullOrEmpty(headers["X-File-Name"])) {
                UploadWholeFile(context, statuses);
            } else {
                UploadPartialFile(headers["X-File-Name"], context, statuses);
            }


            WriteJsonIframeSafe(context, statuses);
        }

        private void UploadPartialFile (string fileName, HttpContext context, List<FilesStatus> statuses) {
            if (context.Request.Files.Count != 1) throw new HttpRequestValidationException("Attempt to upload chunked file containing more than one fragment per request");
            Stream inputStream = context.Request.Files[0].InputStream;
            string fullName = ingestPath + Path.GetFileName(fileName);

            using (FileStream fs = new FileStream(fullName, FileMode.Append, FileAccess.Write)) {
                byte[] buffer = new byte[1024];

                int l = inputStream.Read(buffer, 0, 1024);
                while (l > 0) {
                    fs.Write(buffer,0,l);
                    l = inputStream.Read(buffer, 0, 1024);
                }
                fs.Flush();
                fs.Close();
            }
            FilesStatus MyFileStatus = new FilesStatus();
            MyFileStatus.thumbnail_url = "Thumbnail.ashx?f=" + fileName;
            MyFileStatus.url = "Upload.ashx?f=" + fileName;
            MyFileStatus.name = fileName;
            MyFileStatus.size = (int)(new FileInfo(fullName)).Length;
            MyFileStatus.type = "image/png";
            MyFileStatus.delete_url = "Upload.ashx?f=" + fileName;
            MyFileStatus.delete_type = "DELETE";
            MyFileStatus.progress = "1.0";

          /*  {
                thumbnail_url = "Thumbnail.ashx?f=" + fileName,
                url = "Upload.ashx?f=" + fileName,
                name = fileName,
                size = (int)(new FileInfo(fullName)).Length,
                type = "image/png",
                delete_url = "Upload.ashx?f=" + fileName,
                delete_type = "DELETE",
                progress = "1.0"
            };
            */
            statuses.Add(MyFileStatus);

        }

        private void UploadWholeFile(HttpContext context, List<FilesStatus> statuses) {
            for (int i = 0; i < context.Request.Files.Count; i++) {
                HttpPostedFile file = context.Request.Files[i];
                file.SaveAs(ingestPath + Path.GetFileName(file.FileName));
                string fileName = Path.GetFileName(file.FileName);
                FilesStatus MyFileStatus = new FilesStatus();
                MyFileStatus.thumbnail_url = "Thumbnail.ashx?f=" + fileName;
                MyFileStatus.url = "Upload.ashx?f=" + fileName;
                MyFileStatus.name = fileName;
                MyFileStatus.size = file.ContentLength;
                MyFileStatus.type = "image/png";
                MyFileStatus.delete_url = "Upload.ashx?f=" + fileName;
                MyFileStatus.delete_type = "DELETE";
                MyFileStatus.progress = "1.0";
                statuses.Add(MyFileStatus);
            }
        }

        private void WriteJsonIframeSafe(HttpContext context, List<FilesStatus> statuses) {
            context.Response.AddHeader("Vary", "Accept");
            try {
                if (context.Request["HTTP_ACCEPT"].Contains("application/json")) {
                    context.Response.ContentType = "application/json";
                } else {
                    context.Response.ContentType = "text/plain";
                }
            } catch {
                context.Response.ContentType = "text/plain";
            }

            string jsonObj = js.Serialize(statuses.ToArray());
            context.Response.Write(jsonObj);
        }

        private void ServeFile (HttpContext context) {
            if (string.IsNullOrEmpty(context.Request["f"])) ListCurrentFiles(context);
            else DeliverFile(context);
        }

        private void DeliverFile (HttpContext context) {
            string filePath = ingestPath + context.Request["f"];
            if (File.Exists(filePath)) {
                context.Response.ContentType = "application/octet-stream";
                context.Response.WriteFile(filePath);
                context.Response.AddHeader("Content-Disposition", "attachment, filename=\"" + context.Request["f"] + "\"");
            } else {
                context.Response.StatusCode = 404;
            }
        }

        private void ListCurrentFiles (HttpContext context) {
            List<FilesStatus> files = new List<FilesStatus>();

            string[] names = Directory.GetFiles(@"C:\temp\ingest", "*", SearchOption.TopDirectoryOnly);

            foreach (string name in names) {
                FileInfo f = new FileInfo(name);
                FilesStatus MyFileStatus = new FilesStatus();
                MyFileStatus.thumbnail_url = "Thumbnail.ashx?f=" + f.Name;
                MyFileStatus.url = "Upload.ashx?f=" + f.Name;
                MyFileStatus.name = f.Name;
                MyFileStatus.size = (int)f.Length;
                MyFileStatus.type = "image/png";
                MyFileStatus.delete_url = "Upload.ashx?f=" + f.Name;
                MyFileStatus.delete_type = "DELETE";

                files.Add(MyFileStatus);
                /*files.Add(new FilesStatus
                {
                    thumbnail_url = "Thumbnail.ashx?f=" + f.Name,
                    url = "Upload.ashx?f=" + f.Name,
                    name = f.Name,
                    size = (int)f.Length,
                    type = "image/png",
                    delete_url = "Upload.ashx?f=" + f.Name,
                    delete_type = "DELETE"
                });*/
            }

            context.Response.AddHeader("Content-Disposition", "inline, filename=\"files.json\"");
            string jsonObj = js.Serialize(files.ToArray());
            context.Response.Write(jsonObj);
            context.Response.ContentType = "application/json";
        }
    }
}

使用制度;
使用System.Collections.Generic;
使用System.IO;
使用System.Security.AccessControl;
使用System.Web;
使用System.Web.Script.Serialization;
命名空间jQueryUploadTest{
公共类上载:IHttpHandler{
公共类文件状态
{
公共字符串缩略图\u url{get;set;}
公共字符串名称{get;set;}
公共字符串url{get;set;}
公共整数大小{get;set;}
公共字符串类型{get;set;}
公共字符串delete_url{get;set;}
公共字符串delete_类型{get;set;}
公共字符串错误{get;set;}
公共字符串进度{get;set;}
}
私有只读JavaScriptSerializer js=新JavaScriptSerializer();
私有字符串路径;
公共布尔可重用{get{return false;}}
公共void ProcessRequest(HttpContext上下文){
//var r=context.Response;
ingestPath=@“C:\temp\ingest\”;
AddHeader(“Pragma”,“无缓存”);
AddHeader(“缓存控制”,“私有,无缓存”);
HandleMethod(上下文);
}
私有void HandleMethod(HttpContext上下文){
开关(context.Request.HttpMethod){
案例“头”:
案例“GET”:
服务文件(上下文);
打破
案例“职位”:
上传文件(上下文);
打破
案例“删除”:
删除文件(上下文);
打破
违约:
context.Response.ClearHeaders();
context.Response.StatusCode=405;
打破
}
}
私有void DeleteFile(HttpContext上下文){
字符串filePath=ingestPath+context.Request[“f”];
if(File.Exists(filePath)){
File.Delete(文件路径);
}
}
私有void上载文件(HttpContext上下文){
列表状态=新列表();
System.Collections.Specialized.NameValueCollection headers=context.Request.headers;
if(string.IsNullOrEmpty(头[“X-File-Name”])){
UploadWholeFile(上下文、状态);
}否则{
UploadPartialFile(标题[“X-File-Name”]、上下文、状态);
}
WriteJsonIframeSafe(上下文、状态);
}
私有void UploadPartialFile(字符串文件名、HttpContext上下文、列表状态){
如果(context.Request.Files.Count!=1)抛出新的HttpRequestValidationException(“尝试上载每个请求包含多个片段的分块文件”);
Stream inputStream=context.Request.Files[0]。inputStream;
字符串fullName=ingestPath+Path.GetFileName(文件名);
使用(FileStream fs=newfilestream(全名、FileMode.Append、FileAccess.Write)){
字节[]缓冲区=新字节[1024];
intl=inputStream.Read(缓冲区,0,1024);
而(l>0){
fs.写入(缓冲区,0,l);
l=inputStream.Read(缓冲区,0,1024);
}
fs.Flush();
fs.Close();
}
filestatus MyFileStatus=newfilestatus();
MyFileStatus.thumboil\u url=“thumboil.ashx?f=“+fileName;
MyFileStatus.url=“Upload.ashx?f=“+文件名;
MyFileStatus.name=文件名;
MyFileStatus.size=(int)(新文件信息(全名)).Length;
MyFileStatus.type=“image/png”;
MyFileStatus.delete_url=“Upload.ashx?f=“+fileName;
MyFileStatus.delete_type=“delete”;
MyFileStatus.progress=“1.0”;
/*  {
thumbnail\u url=“thumbnail.ashx?f=“+文件名,
url=“Upload.ashx?f=“+文件名,
name=文件名,
size=(int)(新文件信息(全名)).Length,
type=“image/png”,
delete_url=“Upload.ashx?f=“+文件名,
删除\u type=“删除”,
progress=“1.0”
};
*/
status.Add(MyFileStatus);
}
私有void UploadWholeFile(HttpContext上下文,列表状态){
for(int i=0;i public string thumbnail_url { get; set; }
<%@ WebHandler Language="C#" Class="jQueryUploadTest.Upload" %>
public class FilesStatus
{

    private string m_thumbnail_url;
    private string m_name;
    private string m_url;
    private int m_size;
    private string m_type;
    private string m_delete_url;
    private string m_delete_type;
    private string m_error;
    private string m_progress;

    public string m_thumbnailurl { get { return m_thumbnail_url; } set { m_thumbnail_url = value; } }
    public string name { get { return m_name; } set { m_name = value; } }
    public string url { get { return m_url; } set { m_url = value; } }
    public int size { get { return m_size; } set { m_size = value; } }
    public string type { get { return m_type; } set { m_type = value; } }
    public string m_deleteurl { get { return m_delete_url; } set { m_delete_url = value; } }
    public string m_deletetype { get { return m_delete_type; } set { m_delete_type = value; } }
    public string error { get { return m_error; } set { m_error = value; } }
    public string progress { get { return m_progress; } set { m_progress = value; } }
}