Click here to Skip to main content
15,894,410 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello All,
How To Show alert message when file is already taken(When Browsing for a new file) in asp.net..

Any Suggestions...
Posted
Updated 3-Oct-12 19:30pm
v2
Comments
Rockstar_ 4-Oct-12 1:31am    
Can you please elaborate your problem?
cunny 4-Oct-12 1:46am    
What i meant to say is...If user browse some file,if file is already taken then it must show a alert message saying that file is already taken?
Sergey Alexandrovich Kryukov 4-Oct-12 1:32am    
What is "browsing for a file"? What is unclear: File.Exists or showing?
--SA
cunny 4-Oct-12 1:46am    
What i meant to say is...If user browse some file,if file is already taken then it must show a alert message saying that file is already taken?
Sergey Alexandrovich Kryukov 4-Oct-12 2:40am    
OK, that was my guess, thank you for clarification. Please see the answer.
--SA

C#
/*To get user uploaded file name*/
UploadedFile filename = rauPIAMSpeRateLetter.UploadedFiles[0];
strGetFileName = filename.GetName();

                             /*Path to save user uploaded file(Store your path in hidden field)*/
                                string strFileName = hdfUploadPath.Value + strGetFileName;

                                /*Check for existence of file if not exists then I am saving else I am giving message to user*/
                                if (!File.Exists(strFileName))
                                {
                                    filename.SaveAs(strFileName, true);
                                }
                                else
                                {
                                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Error", "alert('File already exist or rename file then upload');", true);
                                    return;
                                }
 
Share this answer
 
v2
Comments
cunny 4-Oct-12 6:29am    
Thanku Nagaraj :)
It partially worked for me..!!!
Sergey Alexandrovich Kryukov 8-Mar-13 21:24pm    
Correct, a 5.
—SA
File exists: System.IO.File.Exists.

Showing: many methods are available; I would recommend this:
HTML
<p><% some_C#_expression_calculating_the_message_text %></p>


Note that the by existing file you can only mean some file in the file system of the host where the HTTP server works. Consequently, you can only calculate existence on the server part, which makes the "showing" easy: the content is returned in the HTTP response anyway.

—SA
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900