开发者

File Replace Confirmation

I am developing an ASP.NET 3.5 web application which allows users to upload files to the server. If the user is uploading a file which is already there in the folder th开发者_运维百科en I want to show a ASP.NET AJAX modal popup asking the user whether he wants to replace the existing file or not and continue the operation depending on the user's input. Is there a way to do this?


AFAIK, there is no out-of-the-box functionality to do this. You will have to check for the file existence in code and then display the question.


You don't mention whether you're uploading the file by AJAX or the good'ol fashion way. Since I doubt you'd be asking this question if you were uploading through AJAX (seeing it would be trivial to do this), I have to assume that you're not uploading through AJAX, but that you'd like an AJAX window anyway.

The only way I can think of to do that, is by checking for the file's existence through an AJAX call before you start uploading. This is because when you upload the file, there is no way for the browser to send information back until the upload is complete, and even then you can't use AJAX because the call has to be initiated as an AJAX call as well.

So:

  1. User enters file.
  2. BEFORE sending the file, an AJAX call is made to check whether the file exists
  3. If file exists, ask user, submit form if user wants to replace the file and cancel otherwise.
  4. If file does not exist, submit form.

Hope this helps!


You will need to try the upload using an AJAX call, just sending the filename - the server side method could check for file existence and respond with an error if one exists.

If no error is returned, you can proceed with the upload without the question.

If an error was returned (indicating the file exists), ask the question and follow the users response.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜