Last post Mar 12, 2020 02:19 PM by MVC_user
Mar 12, 2020 12:49 PM|MVC_user|LINK
This is my controller:
public JsonResult Remove(HttpPostedFileBase file, string fileguid, string FileName)
ArticleViewModel viewModel = new ArticleViewModel();
viewModel.File = file;
viewModel.ImageGuid = fileguid;
bool isSaved = viewModel.RemoveImages();
I receive an HttpPostedFileBase file such as Original.png , a guid (doesnt matter) and a string such as AnotherName
I want to rename the file before continue but this class has the FileName as get; Read Only.
How can i override this option to change the FileName?
Mar 12, 2020 01:13 PM|mgebhard|LINK
Just "Save As" the file with whatever name you like. This concept is openly covered in the documentation.
Mar 12, 2020 01:17 PM|PatriceSc|LINK
This is the client side name of the posted file and it woouldn't make sense to change this value (you don't expect this name to be change on the user disk ? This is just not possible). I believe you asked something similar already ?
I expect you have somewhere something such as https://docs.microsoft.com/en-us/dotnet/api/system.web.httppostedfilebase.saveas?view=netframework-4.8 which
allow to save the file on the server side using the name you want.
If it doesn't help, explain maybe what you are trying to do (but changing a file name on the client disk is just not possible for obvious reasons).
Edit: you are trying to let users to upload files and then complete an operation such as what is found in most if not all webmails ??? You likely generate a guid for the message, then combine that guid with the name for example to upload file(s) and when
the mail is sent you know which files were uploaded for this message.
Mar 12, 2020 02:19 PM|MVC_user|LINK