4

我在共享点页面上有一些由 JQuery 生成的 html。我想在这个 html 中使用 uploadify 将文件上传到服务器。Alexander通过提供以下部分基于http://www.uploadify.com/forum/viewtopic.php?f=5&t=45的示例代码提供了帮助。

上传.ashx

<%@ Assembly Name="ClassName, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f099e668beaaa0f9" %>
<%@ WebHandler Language="C#" CodeBehind="Upload.ashx.cs" Class="Site.RootFiles.TEMPLATE.LAYOUTS.other.Upload" %>

上传.ashx.cs

public class Upload : IHttpHandler
{
    public void ProcessRequest(HttpContext context) {
    HttpPostedFile oFile = context.Request.Files["Filedata"];

   if (oFile != null) {
   const string sDirectory = "c:\\";
   if (!Directory.Exists(sDirectory))
   Directory.CreateDirectory(sDirectory);

   oFile.SaveAs(Path.Combine(sDirectory, oFile.FileName));

   context.Response.Write("1");
        }
        else {
            context.Response.Write("0");
        }
    }
    public bool IsReusable {
        get {
            return false;
        }
    }
}

该文件未上传到服务器。唯一抛出的事件是 onProgress 事件。导航到 _layouts/other/Upload.ashx 返回 0(这是正确的),因此文件在那里。

主要问题是如何让这个与分享点一起玩?我尝试远程调试 upload.ashx 文件,但它不允许我在 VS 中添加断点,因此远程调试什么也不做。

更新 1

这个问题Visual Studio ASHX 文件调试得到了调试工作。

当我直接导航到页面时,0 被写入页面。调试器触发,一切都很好。当脚本运行时,它没有命中 Upload.ashx,因为没有命中断点。我想我对 Upload.ashx 的引用不正确。我尝试在 js 中使用http://mysite/_layouts/other/Upload.ashx仍然没有乐趣......

更新 2

经过一些测试,问题似乎是它要求我再次登录 Share Point(我已登录)。这导致它绊倒。任何想法如何确保我的身份验证被拾起?

更新 3

这真的很奇怪。我很想说这是我的 IE8 中的一个设置,因为它适用于队友。

当我直接浏览到 /_layouts/other/Upload.ashx 时,我从未被要求进行身份验证。当我通过 JS 访问时,即使我以前登录过,有时也会被要求进行身份验证。

4

1 回答 1

1

您不会上传到页面,而是上传到http 处理程序。您应该添加粘贴到upload.ashx的代码,如论坛帖子中所述。然后,在客户端,像这样使用uploadify:

$("#fileInput1").uploadify ({ script: 'upload.ashx' });
于 2009-08-25T12:36:56.463 回答