将 Uploadify 与 Sharepoint 和 .net 结合使用
-
19-09-2019 - |
题
我在共享点页面上有一些由 JQuery 生成的 html。我想在这个 html 中使用 uploadify 将文件上传到服务器。 亚历山大 通过提供以下示例代码来提供帮助,该代码部分基于 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 的引用是不正确的。我尝试使用 http://mysite/_layouts/other/Upload.ashx 在 js 中仍然没有欢乐......
更新2
经过一些测试后,问题似乎是它要求我再次登录 Share Point(我已登录)。这导致它绊倒。有什么想法可以确保我的身份验证被接受吗?
更新3
这实在是太奇怪了。我很想说这是我的 IE8 中的一个设置,它是为队友工作的。
当我直接浏览到 /_layouts/other/Upload.ashx 时,从未要求我进行身份验证。当我通过 JS 访问时,即使我之前已经登录过,有时也会要求进行身份验证。
解决方案
您不是上传到页面,而是上传到 http处理程序. 。您应该将粘贴到的代码添加到 上传.ashx, ,如论坛帖子中所指定。然后,在客户端上使用 uploadify,如下所示:
$("#fileInput1").uploadify ({ script: 'upload.ashx' });