Message pop-up for throw catch exception

Jason Phang

Well-known member
Joined
Aug 13, 2019
Messages
46
Programming Experience
Beginner
The code block below is supposed to sort of compare the hash value of the files and if there is an existing hash, then a message should be notified to the user that it is a duplicate. For now, i am able to see it from the throw catch exception. I just wanted like an error message to be displayed.
public static void compareHash(string path) { DriveService service = GetService(); FilesResource.ListRequest FileListRequest = service.Files.List(); IList<Google.Apis.Drive.v3.Data.File> files = FileListRequest.Execute().Files; List<GoogleDriveFiles> FileList = new List<GoogleDriveFiles>(); foreach (var file in files) { if (file.Md5Checksum.Equals(path)) { throw new Exception("File already exists"); }} }

This is the code for my upload button.

<label for="file">Upload file:</label> <input type="file" name="file" id="file" /> <input type="submit" value="Upload" id="fileUpload" />
For that case, since this program is an ASP.NET. is there a way for me to like display a pop-up message once the exception is displayed? Do i run it from razor or i can do it from asp.net?
 
Okay, if that is the case, then for the part where I wrote if (file.Md5Checksum.Equals(path)) { throw new Exception("File already exists"); } is there any other way, where I can like return something like instead of a message but like an indicator to the C# that it is a same hash? Because I would display the error message from the razor part
 
It's not rocket science. Pop a message where ever you want :
C#:
Response.Write("<script>alert('Msg here');</script>");
 
instead of a message but like an indicator to the C# that it is a same hash?
You are changing what you asked for, which is a different question. One which you should open a new topic for. However, there is a link to conditional logic in my signature, which is something you seem familier with since you are already using it above.

There is nothing stopping you from checking if two hashes are the same and taking the appropriate action. Sorry I missed that last part of your post, which is why I'm only answering it now. It's been a hectic day here.
 
Back
Top Bottom