0

下面的代码用于将文件复制到目录中,但我继续收到异常“C:\Program Files (x86)\Common Files\Microsoft Shared\DevServer\10.0\abc.jpg”文件未找到错误。感谢您的任何帮助或想法。我在 Windows 7 机器上使用 VS2010、jQuery 1.8.1 (min)、IIS 7。我的 webconfig 和元素中都有 FileUpload.ashx。

此问题仅在使用 FireFox 时发生。

HTML 标记

    var FileName = null;     

$.ajax({ type: "POST",
            url: "FileUpload.ashx",
            data: { FileName: FileName },
            async: true,
            success: function (data) {
                alert("Success");
                }
            },
            error: function (data) {
                alert("Error");
            }
        });
    });

   function setFileName(e) {
        FileName = e.value;         
    }

FileUpload 背后的代码

public void ProcessRequest(HttpContext context)
    {

        try
        {

            String FileID = Guid.NewGuid().ToString();


            String sDirectory = "~/UploadedFiles/";
            String sFileName = context.Request["FileName"];
            String sUploadPath = String.Format("{0}/{1}", sDirectory, sFileName);
            sUploadPath = context.Server.MapPath(sUploadPath);


            string FileName = context.Request["FileName"];
            FileInfo fn = new FileInfo(FileName);

            fn.CopyTo(sUploadPath + FileID + "_" + fn.Name);

     }

     catch (Exception ex)
         {
    string message = ex.Message;
         }

      }
4

0 回答 0