Verify if file exists or not in C#

后端 未结 12 1357
名媛妹妹
名媛妹妹 2020-12-15 17:19

I am working on an application. That application should get the resume from the users, so that I need a code to verify whether a file exists or not.

I\'m using ASP.N

12条回答
  •  旧巷少年郎
    2020-12-15 17:46

    Try this:

         string fileName = "6d294041-34d1-4c66-a04c-261a6d9aee17.jpeg";
    
         string deletePath= "/images/uploads/";
    
         if (!string.IsNullOrEmpty(fileName ))
            {
                // Append the name of the file to previous image.
                deletePath += fileName ;
    
                if (File.Exists(HttpContext.Current.Server.MapPath(deletePath)))
                {
                    // deletevprevious image
                    File.Delete(HttpContext.Current.Server.MapPath(deletePath));
                }
            }
    

提交回复
热议问题