Convert a path (which is an image) to HttpPostedFileBase

I provide for the User to upload an image.

But if it is not done, I want to set a default image in an images folder.

How do I set the model property of type 'HttpPostedFileBase' to the image that is located at the path that I set programmatically?

The model property:

 public HttpPostedFileBase UploadedImage { get; set; }

I have tries these with no success.

This one I get: Cannot convert type 'string' to 'System.Web.HttpPostedFileBase'.

 if (userProfileForSaveVM.UserProfileSingleVM.UploadedImage == null)
 {
   // Set a default.
   userProfileForSaveVM.UserProfileSingleVM.UploadedImage = 
   "F:\\GbngWebClient\\GbngWebClient\\Images\\Avatar.png";
 }

This one I get: property or indexer 'HttpPostedFileBaseInputStream' cannot be assigned to -- it is read only.

 if (userProfileForSaveVM.UserProfileSingleVM.UploadedImage == null)
 {
   // Set a default.
   String pathImage = Server.MapPath("F:\\GbngWebClient\\GbngWebClient\\Images\\Avatar.png");
   userProfileForSaveVM.UserProfileSingleVM.UploadedImage.InputStream = new FileStream(pathImage, FileMode.Open);
 }

This one I get: Cannot convert type 'byte[]' to 'System.Web.HttpPostedFileBase'.

 if (userProfileForSaveVM.UserProfileSingleVM.UploadedImage == null)
 {
   // Set a default.
   byte[] imageArray = 
   System.IO.File.ReadAllBytes(@F:\\GbngWebClient\\GbngWebClient\\Images\\Avatar.png");
   userProfileForSaveVM.UserProfileSingleVM.UploadedImage = imageArray;
 }


from Recent Questions - Stack Overflow https://ift.tt/3jdChK2
https://ift.tt/eA8V8J

Comments

Popular posts from this blog

Today Walkin 14th-Sept

Spring Elasticsearch Operations

Hibernate Search - Elasticsearch with JSON manipulation