So I upload the file and add the GUID to the database, and on my index view page, I want to display that file with the original file name in one column and GUID in the next column, Any suggestion?
class define as
public Guid ID { get; set; }
public string FileName { get; set; }
the index controller
public ViewResult Index()
{
return View(uploadedfileRepository.AllIncluding(UploadedFile => UploadedFile.TimeEntrys));
}
and the view
@foreach (var item in Model)
{
<tr>
<td>
@item.ID
</td>
<td>
@item.FileName
</td>
}
So I save the file into my uploadfile database context and try to display that in index view with my origianl file name and guid next to it.
The way I save my file
UploadedFileRepository newUploadedFileRepository = new UploadedFileRepository();
private string _uploadsFolder = HostingEnvironment.MapPath("~/App_Data/Files/");
public Guid SaveUploadedFile(HttpPostedFileBase fileBase)
{
var identifier = Guid.NewGuid();
fileBase.SaveAs(_uploadsFolder + identifier + suffix(fileBase.FileName));
var file = new UploadedFile { FileName = _uploadsFolder + identifier + suffix(fileBase.FileName), ID = Guid.NewGuid() };
_repository.UploadedFiles.Add(file);
return identifier;
}
static string suffix(string filename)
{
string[] names = filename.Split('.');
return "." + names[1].ToString();
}
Instead of returning a Guid, why not return the UploadedFile Type.