Welcome Guest Search | Active Topics | Sign In | Register

AJAXUploader.TempFileName is null Options
Duane
Posted: Friday, September 25, 2009 12:16:19 PM
Rank: Advanced Member
Groups: Member

Joined: 9/4/2007
Posts: 114
I have been using the AJAXUploader with the TempFileLocation set in the tag, but today, I started setting the TempFileLocation in my page_load event from an appSetting in the webconfig. Now, when the form is submitted, the TempFileName property of the AJAXPostedFile class in the AJAXUploader is coming up null. I watched the upload create the three files (.status, .info, .data), but when the form is submitted, the .data file is deleted and the property becomes null.

Here is my implemtation:

Code: HTML/ASPX
<eo:AJAXUploader 
  ID="AJAXUploader1" 
  runat="server" 
  Width="250px"
  AllowedExtension=".flv|.mov|.avi|.wmv|.mpeg|.mp4|.mpeg4|.jpg"
  AutoUpload="false"
  ClientSideOnError="invalidFileExtension">
</eo:AJAXUploader>




Code: C#
// Set Uploader properties
private void SetUploaderProperties()
{
  AJAXUploader1.TempFileLocation = ConfigurationManager.AppSettings["UploaderTempLocation"];
  AJAXUploader1.FinalFileLocation = ConfigurationManager.AppSettings["UploaderFinalFileLocation"];
}

// and the postback method to save the video uploaded:

protected void ui_btn_SaveVideo_Click(object sender, EventArgs e)
{
  foreach (EO.Web.AJAXPostedFile file in AJAXUploader1.PostedFiles)
  {
    //Get the temp file name
    string tempFileName = file.TempFileName;
            
    //Create the final file name based on the original file name
    finalFileName = System.IO.Path.Combine(AJAXUploader1.FinalFileLocation  + @"\", file.ClientFileName);
            
    //Move the file to the desired location
    if (System.IO.File.Exists(finalFileName))
    {
      System.IO.File.Delete(finalFileName);
    }
    System.IO.File.Move(tempFileName, finalFileName);
    break;  // Just grab the first one if the user uploaded more files.
  }
}


This was working before I started setting the Uploader.TempFileLocation and FinalFileLocation from my page_load method, now, the .data file is deleted and the TempFileName ends up null so the .Move method fails.

Why would setting those properties in code cause the .data file be deleted?

Thanks,
Duane
eo_support
Posted: Friday, September 25, 2009 4:36:36 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Hi,

Can you try to set it in your OnInit event and see if it works? The idea is to set those properties as earlier as possible.

Thanks
Duane
Posted: Friday, October 2, 2009 11:45:04 AM
Rank: Advanced Member
Groups: Member

Joined: 9/4/2007
Posts: 114
Hello,

I found the problem to be that when I set the FinalFileLocation property, the file is moved automatically after upload.
I was still trying to move the file in my code.

Thanks
eo_support
Posted: Friday, October 2, 2009 11:49:03 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Duane wrote:
I found the problem to be that when I set the FinalFileLocation property, the file is moved automatically after upload.

Yes. That's exactly how it works. Thanks for the update.


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.