public string uploadimage(HttpPostedFileBase file)
{
Random r = new Random();
string path = "-1";
int random = r.Next();
if (file != null && file.ContentLength > 0)
{
string extension = Path.GetExtension(file.FileName);
if (extension.ToLower().Equals(".jpg") || extension.ToLower().Equals(".jpeg") || extension.ToLower().Equals(".png"))
{
try
{
path = Path.Combine(Server.MapPath("~/Content/upload"), random + Path.GetFileName(file.FileName));
file.SaveAs(path);
path = "~/Content/upload/" + random + Path.GetFileName(file.FileName);
// ViewBag.Message = "File uploaded successfully";
}
catch (Exception ex)
{
path = "-1";
}
}
else
{
Response.Write("<script>alert('Only jpg ,jpeg or png formats are acceptable....'); </script>");
}
}
else
{
Response.Write("<script>alert('Please select a file'); </script>");
path = "-1";
}
return path;
}
Good Work
ReplyDeletethe stay please
ReplyDeletecan we create Blazor page application with MVC
ReplyDeleteHi why is the word Add and Combine has an error?
ReplyDelete