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 http://stackoverflow.com/questions/1334538/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/%5Flayouts/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.