Welcome Guest Search | Active Topics | Sign In | Register

Upload Control (save the file with another name) Options
CatalinD
Posted: Sunday, June 1, 2008 4:58:07 AM
Rank: Newbie
Groups: Member

Joined: 5/23/2008
Posts: 8
Hi,
I would like to know if it’s possible using the upload control to save the file on the server with another name. I need this for the following situation: I have a user which id is tomC and this user upload a file named abc.jpg,; on the server I would like to have tomC_abc.jpg
If yes, could you explain me how I can do this.
Thank you
eo_support
Posted: Sunday, June 1, 2008 8:45:06 AM
Rank: Administration
Groups: Administration

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

You would handle the uploader's FileUploaded event and then rename file there. It will be something like this:

Code: C#
foreach (EO.Web.AJAXPostedFile file in Uploader1.PostedFiles)
{
    //Get the original file name. Note:
    //1. This returns the full file name. For example, if your
    //   FinalFileLocation is set to "c:\upload", this returns
    //   "c:\upload\abc.jpg" instead of "abc.jpg";
    //2. FinalFileName is valid only when FinalFileLocation is
    //   set, when FinalFileLocation is not set, you should use
    //   TempFileName instead
    string fileName = file.FinalFileName;

    //Split the full file name into directory and file name
    string dir = System.IO.Path.GetDirectoryName(fileName);
    string name = System.IO.Path.GetFileName(fileName);

    //Change the file name
    name = "TomC_" + name;

    //Create the new file name
    string newFileName = System.IO.Path.Combine(dir, name);

    //Rename the file
    System.IO.File.Move(fileName, newFileName);
}


Thanks
CatalinD
Posted: Sunday, June 1, 2008 11:15:25 AM
Rank: Newbie
Groups: Member

Joined: 5/23/2008
Posts: 8
Hi,
Thank you for your very quick response. You have a very good client service.
Thank you and good luck


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.