Click here to Skip to main content
12,695,447 members (27,431 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# ASP.NET
Hello All,
How To Show alert message when file is already taken(When Browsing for a new file) in asp.net..

Any Suggestions...
Posted 3-Oct-12 20:29pm
cunny301
Updated 3-Oct-12 20:30pm
v2
Comments
VijayChauhan123 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?
   
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?
   
OK, that was my guess, thank you for clarification. Please see the answer.
--SA
VijayChauhan123 4-Oct-12 2:01am
   
when you select the file , may be you are assigning the path and filename to a variable, based on the content of the variables you can display alert message.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

/*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;
                                }
  Permalink  
v2
Comments
cunny 4-Oct-12 6:29am
   
Thanku Nagaraj :)
It partially worked for me..!!!
   
Correct, a 5.
—SA
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

File exists: System.IO.File.Exists.

Showing: many methods are available; I would recommend this:
<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
  Permalink  
v2

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.170118.1 | Last Updated 4 Oct 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100