Method of uploading and deleting asp. net picture file

  • 2021-07-22 09:30:23
  • OfStack

This paper describes the uploading and deleting methods of asp. net picture files with examples. Share it for your reference, as follows:


// Upload pictures 
public void UpdataImage()
{
  // Get the selected file 
  string fileName = fudImage.FileName;
  // Get suffix name 
  string fileExt = Path.GetExtension(fileName);
  if (fileExt != ".jpg")
  {
   return;
  }
  // Gets the path of the upload on the server side 
  string serverPath = Server.MapPath("/Web/images");
  // Generate Folder 
  string createDirectory = serverPath + "\\" + "Card";
  fudImage.SaveAs(createDirectory + "\\" + fileName);
}
// Delete a file 
public void DelFile(string path)
{
  System.IO.FileInfo file = new FileInfo(path);
  if (file.Exists)
  {
   file.Delete();
  }
}

For more readers interested in asp. net, please check the topics on this site: "Summary of File Operation Skills of asp. net", "Summary of String Operation Skills of asp. net", "Summary of Operation Skills of asp. net", "Summary of Skills of asp. net ajax" and "Summary of Cache Operation Skills of asp. net".

I hope this paper is helpful to everyone's asp. net programming.


Related articles: