将 Uploadify 与 Sharepoint 和 .net 结合使用
我在共享点页面上有一些由 JQuery 生成的 html。我想在这个 html 中使用 uploadify 将文件上传到服务器。 Alexander 提供了以下示例代码,该代码部分基于 http://www.uploadify.com/forum/viewtopic.php?f=5&t=45< /a>.
upload.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" %>
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 访问时,即使我之前已经登录过,有时也会要求进行身份验证。
I have a some html being generated by JQuery on a Share Point page. I want to use uploadify in this html to upload a file to the server. Alexander has helped by providing the following sample code which is based partially on http://www.uploadify.com/forum/viewtopic.php?f=5&t=45.
upload.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" %>
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;
}
}
}
The file is not uploading to the server. The only event being thrown is the onProgress one. Navigating to _layouts/other/Upload.ashx returns 0 (this is correct) so the file is there.
The main question is how do I get this to play with share point? I try remote debugging the upload.ashx file but it won't allow me to add breakpoints in VS so remote debugging does nothing.
Update 1
This question Visual Studio ASHX files debugging got debugging working.
When I navigate directly to the page 0 is written to the page. The debugger fires and everything is good. When the script run it's not hitting Upload.ashx as no breakpoints are hit. I imagine my reference to Upload.ashx is incorrect. I tried using http://mysite/_layouts/other/Upload.ashx in the js and still no joy...
Update 2
After some testing the problem seems to be that it is asking me to log into Share Point again (I am logged in). This is causing it to trip over. Any ideas how to make sure that my authenication is picked up?
Update 3
This is really strange. I am tempted to say it is a setting in my IE8 that is doing it as it works for a team mate.
When I browse directly to /_layouts/other/Upload.ashx it I am never asked to authenticate.
When I go via JS I am sometimes asked to authenicate even if I have logged in before.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不是上传到页面,而是上传到 http 处理程序。您应该按照论坛帖子中的指定,添加粘贴到 upload.ashx 的代码。然后,在客户端上使用 uploadify,如下所示:
You don't upload to a page, but to a http handler. You should add the code that you pasted to a upload.ashx, as specified in the forum post. Then, on the client, use uploadify like this: