C# 试图在C语言中处理AJAX FormData“但是得到”;“请求”;参考是必需的错误

C# 试图在C语言中处理AJAX FormData“但是得到”;“请求”;参考是必需的错误,c#,ajax,C#,Ajax,我试图用下面的代码处理上传的文件,但我得到一个错误,需要Requestreference。我试图添加对system.web.httprequest的引用,但这并没有解决问题 以下是我的方法: [System.Web.Services.WebMethod] public static string UploadFile(string ParentPath) { for (int i = 0; i <

我试图用下面的代码处理上传的文件,但我得到一个错误,需要
Request
reference。我试图添加对
system.web.httprequest
的引用,但这并没有解决问题

以下是我的方法:

 [System.Web.Services.WebMethod]

            public static string UploadFile(string ParentPath)
            {


                for (int i = 0; i <   Request.Files.Count; i++)
                {
                    var file = Requset.Files[i];

                    var fileName = Path.GetFileName(file.FileName);

                    var path = Path.Combine(Server.MapPath("~/Junk/"), fileName);
                    file.SaveAs(path);
                }

            }
[System.Web.Services.WebMethod]
公共静态字符串上载文件(字符串父路径)
{
对于(int i=0;i
使用的
handler.ashx

 public void ProcessRequest(HttpContext content)
        {
            if (content.Request.Files.Count > 0)
            {

                HttpFileCollection files = content.Request.Files;
                for (int i = 0; i < files.Count; i++)
                {
                    HttpPostedFile file = files[i];
                    GSFileInfo fileInfo = new GSFileInfo();
                    using (MemoryStream streamCopy = new MemoryStream())
                    {
                        byte[] fileDataArr = null;
                        content.Request.Files[i].InputStream.CopyTo(streamCopy);
                        string parentPath = content.Request.Form["parentPathHidden"];

                        fileDataArr = streamCopy.ToArray();
                        var test = content.Request.Files[i];

                        string ServerPath = content.Server.MapPath("~/uploads/" + file.FileName);
                        bool read = streamCopy.CanRead;
                        bool write = streamCopy.CanWrite;

                        fileInfo.Name = file.FileName;
                        fileInfo.Path = file.FileName;
                        fileInfo.ParentPath = "root"; //  Need to Read Parent Path From the Request 

                        if (file.ContentType.Contains("image"))
                        {

                            fileInfo.Type = FileType.File;
                        }
                        else
                        {
                            fileInfo.Type = FileType.Folder;
                        }



                        fileInfo.Size = files[i].ContentLength;

                        fileInfo.MD5 = GetMD5(fileDataArr);
                        if (FilesBAL.InsertFile(fileInfo) == DALMessage.Success)
                        {
                            file.SaveAs(ServerPath);
                           content.Response.Write( Home.GetDataByParent("root"));
                        }

                    }
                }
            }
        }
public void ProcessRequest(HttpContext内容)
{
如果(content.Request.Files.Count>0)
{
HttpFileCollection files=content.Request.files;
对于(int i=0;i
使用的
handler.ashx

 public void ProcessRequest(HttpContext content)
        {
            if (content.Request.Files.Count > 0)
            {

                HttpFileCollection files = content.Request.Files;
                for (int i = 0; i < files.Count; i++)
                {
                    HttpPostedFile file = files[i];
                    GSFileInfo fileInfo = new GSFileInfo();
                    using (MemoryStream streamCopy = new MemoryStream())
                    {
                        byte[] fileDataArr = null;
                        content.Request.Files[i].InputStream.CopyTo(streamCopy);
                        string parentPath = content.Request.Form["parentPathHidden"];

                        fileDataArr = streamCopy.ToArray();
                        var test = content.Request.Files[i];

                        string ServerPath = content.Server.MapPath("~/uploads/" + file.FileName);
                        bool read = streamCopy.CanRead;
                        bool write = streamCopy.CanWrite;

                        fileInfo.Name = file.FileName;
                        fileInfo.Path = file.FileName;
                        fileInfo.ParentPath = "root"; //  Need to Read Parent Path From the Request 

                        if (file.ContentType.Contains("image"))
                        {

                            fileInfo.Type = FileType.File;
                        }
                        else
                        {
                            fileInfo.Type = FileType.Folder;
                        }



                        fileInfo.Size = files[i].ContentLength;

                        fileInfo.MD5 = GetMD5(fileDataArr);
                        if (FilesBAL.InsertFile(fileInfo) == DALMessage.Success)
                        {
                            file.SaveAs(ServerPath);
                           content.Response.Write( Home.GetDataByParent("root"));
                        }

                    }
                }
            }
        }
public void ProcessRequest(HttpContext内容)
{
如果(content.Request.Files.Count>0)
{
HttpFileCollection files=content.Request.files;
对于(int i=0;i