Uploading file

  1. #1

    Uploading file

    Hi,

    I want to use the button only method to attach a file to the FileUploadField. However, when I call the controller action, I get a null file.

    The relevant code is as such:

    //Inside View
     X.FileUploadField()
       .Listeners(ld => ld.Change.Handler = "#{DirectMethods}.FileUpload()")
       .ButtonOnly(true)
       .ButtonText("Open..."),
    
    //Controller Action
     [DirectMethod]
     public ActionResult FileUpload()
     {
       if (this.GetCmp<FileUploadField>("FileUploadField1").HasFile)  //This section never runs 
       {
          HttpPostedFile file = this.GetCmp<FileUploadField>("FileUploadField1").PostedFile;
    
          var filename = Path.GetFileName(file.FileName);
          var path = Path.Combine(Server.MapPath("~/Content/images"), filename);
          file.SaveAs(path);
       }
    
       DirectResult result = new DirectResult();
       result.IsUpload = true;
       return result;
     }
    Any help is much appreciated.
    Last edited by massman07; Aug 12, 2014 at 7:45 PM.
  2. #2
    Hi,

    form is required to upload the file (html form or from panel)
  3. #3
    Also, need to set IsUpload=true for direct method attribute
  4. #4
    Thanks for the quick reply,

    I am actually trying to have a the File Upload window come up from pressing a menu item like bellow:

     X.MenuPanel()
        .Region(Region.North)
        .Title("IDS Planner : " + @User.Identity.Name)
        .ID("North")
        .TopBar(X.Toolbar()
            .Items(             
                X.Button()
                .Text("File")
                .Menu(X.Menu()
                    .Items(
                        X.FormPanel()
                        .Items(
                            X.FileUploadField()
                            .Listeners(ld => ld.Change.Handler = "#{DirectMethods}.FileUpload()")
                            .ButtonOnly(true)
                            .ButtonText("Open...")
                        ),
                        X.MenuItem()
                        .Text("Set Connection String")
                        .DirectClickAction("ConnStrForm","Data"),
                        X.MenuItem()
                        .Text("Save..."),
                        X.MenuItem()
                        .Text("Close")
                        )
                )
    Adding a form panel inside this menu creates a strange appearance, Is it possible do this by hiding the form field and only showing the "Open..." button? Also, would you be able to provide some sample code on where and how to use the IsUpload attribute?

    Thanks in advance

Similar Threads

  1. Multiple File Uploading
    By Rupesh in forum 1.x Help
    Replies: 0
    Last Post: Nov 28, 2013, 9:49 AM
  2. [CLOSED] How to identify upload file size before uploading in IE?
    By rnachman in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Jun 29, 2012, 5:54 PM
  3. [CLOSED] Error when uploading file to httphandler
    By jchau in forum 1.x Legacy Premium Help
    Replies: 5
    Last Post: Nov 09, 2011, 1:32 PM
  4. [CLOSED] Uploading files
    By r_honey in forum 1.x Legacy Premium Help
    Replies: 27
    Last Post: Aug 04, 2010, 6:20 PM
  5. Replies: 2
    Last Post: Jun 30, 2010, 5:00 AM

Tags for this Thread

Posting Permissions