locked
Is it any point to use AsyncFileUpload instead of FileUpload when I upload to a ftp server RRS feed

  • Question

  • User1366894300 posted

    In the present solution I use the standard FileUpload control. Note I upload the image file to a FTP server.
    Below is the code I use to upload the image file to the ftp server

    Now to my question: What would be the advantages if I instead use a AsyncFileUpload instead of the standard FileUpload that I use now ?

    What I actually want is to display all the image files that have been uploaded without the page flicker(when a new page is rendered)
    I want a partial update of my aspx page where only the uploaded image files is updated.

    I mean I can probably do this by using the update panel and still use the standard FileUpload.

    One more question.
    When I use the FileUpload will a full rendered page be passed back to the browser ?


    //Code
    ******

    protected void BtnUploadBild_Click(object sender, EventArgs e)
         {
             if (!FileUploadBild1.HasFile)
             {
                 this.lblWarningBild.Text = "Ladda först upp en bild ...";
             }
             else if (Path.GetExtension(FileUploadBild1.FileName).ToLower() != ".jpg" &&
                         Path.GetExtension(FileUploadBild1.FileName).ToLower() != ".png" &&
                         Path.GetExtension(FileUploadBild1.FileName).ToLower() != ".gif")
             {
                 this.lblWarningBild.Text = "Andast följande filtyper godkänns (jpg,png,jpg)";
             }
             else
             {
                 try
                 {
                     File.Delete(path + FileUploadBild1.FileName);

                     FileUploadBild1.PostedFile.SaveAs(path + FileUploadBild1.FileName);
                     path += FileUploadBild1.FileName;

                     FileManager.HandleUpload(path, lblID.Text);

                     backEnd.InsertIntoPictures(lblID.Text, FileUploadBild1.FileName);

                     File.Delete(path);
                 }
                 catch (Exception ex)
                 {
                     FileManager.EventLogger("BtnUploadBild_Click misslyckades", ex.Message);
                     throw ex;
                 }

                 //refresh
                 DisplayCaseDetail(this.lblID.Text);
             }
         }

    public static void HandleUpload(string path, string caseID)
        {
            try
            {
                FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ftpServer + caseID);
                request.Credentials = new NetworkCredential(userName, passWord);
                request.Method = WebRequestMethods.Ftp.MakeDirectory;
                using (FtpWebResponse FTPRes = (FtpWebResponse)request.GetResponse())
                {
                    UploadFile(caseID, path);
                }
            }
            catch (WebException ex)
            {
                if (ex.Response != null)
                {
                    if (((FtpWebResponse)ex.Response).StatusCode == FtpStatusCode.ActionNotTakenFileUnavailable)
                    {
                        UploadFile(caseID, path);
                    }
                }
            }
        }

    //Tony

    Saturday, January 18, 2014 5:52 AM

Answers

  • User-417640953 posted

    Hi Tojo,

    Thank you post the issue to asp.net forum.

    Due to security reasons, browsers don't let you post files via javascript.

    So the UploadFile will not work with a partial post back, and it also not working with UpdatePanel without full postback.

    "AsyncFileUpload is an ASP.NET AJAX Control that allows you asynchronously upload files to server. 

    The file uploading results can be checked both in the server and client sides."

    If you choice to use AsyncFileUpload to upload the file asynchronously, you can use its method UploadedComplete to complete it.

    For how to use it, please follow below tutorials.

    http://www.asp.net/AjaxLibrary/AjaxControlToolkitSampleSite/AsyncFileUpload/AsyncFileUpload.aspx

    Hope this helps, thanks.

    Best Regards!

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, January 20, 2014 10:20 PM