|
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
|
|
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
|
|
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
|
|