hanan-mstudio
hanan-mstudio

Reputation: 171

Rename file after upload and saved

I have build a nice uploading system to upload file and save it on the server where the user can also upload multiple files at once. The files are saved to different directories depending upon where the user wants to save them. There is also an access database with users and the file name they upload, so every user has his own list of files. I did it so that the user can delete only his files and download all the others.

Now the user wants to be able to change the file name after it has been uploaded. I have no idea how to do it, the question is if that is even possible? Can I add a button so that when the user clicks on it I shows a textbox where the user can enter the new name and after that he clicks save and the file name changes on the file itself and on the access table?

Can it be done with AJAX when I send the old name and the new name?

I working on asp.net and C# I hope I explain myself.

Upvotes: 0

Views: 1918

Answers (2)

SamTech
SamTech

Reputation: 1313

You can do it either with asp.net page or web service. Create a new asp.net page, add there code to rename file

System.IO.File.Move(@"some\path\file1.jpg", @"some\path\file2.jpg");
System.IO.File.Delete(@"some\path\file1.jpg");
...
<write here code to update access database>

Call that page from ajax.

Upvotes: 1

LittleSweetSeas
LittleSweetSeas

Reputation: 7054

For sure it is possible, you have a function "System.IO.File.Rename(string oldName, string newName)" - check it, I may not remember it exactly. You can do it with AJAX without any issue at all. Just be sure you have write permission to the file (you should already have that if you just uploaded that file).

Upvotes: 0

Related Questions