Reputation: 2682
I have form with dynamic file upload:
var ordinaryPropertyValue = new Catalog.Core.Entities.OrdinaryPropertyValue();
var fileFile = Request.Files["File" + prop.Id];
if (fileFile == null) continue;
string pathFile = Server.MapPath("~/temp");
string filenameFile = Path.GetFileName(fileFile.FileName);
if (!string.IsNullOrEmpty(filenameFile)) {
fileFile.SaveAs(Path.Combine(pathFile, filenameFile));
ordinaryPropertyValue.Value = Path.Combine(pathFile, filenameFile);
instance.SetPropertyValue(prop.Id, ordinaryPropertyValue);
}
How can I rename files which are submiited from users?
Upvotes: 0
Views: 4475
Reputation: 3883
just set file name you want in this line
String filenameFile = "MyFile.ext";
String pathFile = Server.MapPath("~/temp/" + filenameFile);
fileFile.SaveAs(pathFile);
this will save your file in path ~/temp/MyFile.ext
Upvotes: 2