Click here to Skip to main content
Rate this: bad
good
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 19:29pm
cunny301
Edited 3-Oct-12 19:30pm
v2
Comments
VijayChauhan123 at 4-Oct-12 1:31am
   
Can you please elaborate your problem?
cunny at 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 at 4-Oct-12 1:32am
   
What is "browsing for a file"? What is unclear: File.Exists or showing?
--SA
cunny at 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 at 4-Oct-12 2:40am
   
OK, that was my guess, thank you for clarification. Please see the answer.
--SA
VijayChauhan123 at 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 at 4-Oct-12 6:29am
   
Thanku Nagaraj :)
It partially worked for me..!!!
Sergey Alexandrovich Kryukov at 8-Mar-13 21:24pm
   
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
0 OriginalGriff 330
1 Sergey Alexandrovich Kryukov 295
2 ClimerChinna 207
3 Magic Wonder 205
4 Gihan Liyanage 192
0 Sergey Alexandrovich Kryukov 8,188
1 OriginalGriff 6,991
2 CPallini 2,598
3 Richard MacCutchan 1,925
4 Abhinav S 1,736


Advertise | Privacy | Mobile
Web01 | 2.8.140826.1 | Last Updated 4 Oct 2012
Copyright © CodeProject, 1999-2014
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