2

I am using Ext.Net library along with ASP.net routing.

The following page

~/Admin/Dashboard.aspx

is routed as

administrator/fr/dashboard/

or

administrator/en/dashboard/

I am using Ext.Net FileUpload control.

The following code (on a direct event)

HttpContext.Current.Request.Files[0].SaveAs(fileName);

produces the following exception

System.Web.HttpException (0x80004005): The file '/administrator/en/dashboarddefault.aspx' does not exist. at Ext.Net.HandlerMethods.GetHandlerMethods(HttpContext context, String requestPath) at Ext.Net.HandlerMethods.GetHandlerMethods(HttpContext context, String requestPath) at Ext.Net.DirectRequestModule.ProcessRequest(HttpApplication app, HttpRequest request)

with Status Code: 200, Status Text: OK.

If I do the same thing from

~/Admin/Dashboard.aspx

There is no problem.

Please help.

Nancy
  • 147
  • 2
  • 18

1 Answers1

0

Try to use Generic handlers.

upload.ashx :

<%@ WebHandler Language="C#" Class="upload" %>

using System;
using System.Web;
using System.IO;
using System.Web.Script.Serialization;

public class upload : IHttpHandler {

    public void ProcessRequest (HttpContext context) {
        try
        {
            HttpPostedFile postedFile = context.Request.Files[0];
            byte[] b = new byte[postedFile.ContentLength];
            postedFile.InputStream.Read(b, 0, postedFile.ContentLength);
            File.WriteAllBytes(Path.GetTempPath() + postedFile.FileName, b);
            context.Response.Write((new JavaScriptSerializer()).Serialize(new { success = true }));
        }
        catch (Exception ex)
        {
            context.Response.Write((new JavaScriptSerializer()).Serialize(new { success = false, error = ex.Message }));
        }
    }

    public bool IsReusable {
        get {
            return false;
        }
    }

}

js code (you can adapt him to Ext.Net or use CustomConfig), put this code to form items array:

{
    xtype: 'fileuploadfield',
    listeners: {
        change: function () {
            var fp = this.findParentByType('panel');
            if (fp.getForm().isValid()) {
                fp.getForm().submit({
                    url: 'Handlers/upload.ashx',
                    success: function (me, o) {
                        if (o.result.success) {
                            // some code
                        } else {
                            Ext.Msg.alert('Error', o.result.error);
                        }
                    }
                });
            }
        }
    }
}
Boris Gappov
  • 2,483
  • 18
  • 23