Click here to Skip to main content
Sign Up to vote bad
good
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:29
cunny303
Edited 3 Oct '12 - 19:30

Comments
VijayChauhan123 - 4 Oct '12 - 1:31
Can you please elaborate your problem?
cunny - 4 Oct '12 - 1:46
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:32
What is "browsing for a file"? What is unclear: File.Exists or showing? --SA
cunny - 4 Oct '12 - 1:46
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:40
OK, that was my guess, thank you for clarification. Please see the answer. --SA
VijayChauhan123 - 4 Oct '12 - 2:01
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.

2 solutions

/*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  
Comments
cunny - 4 Oct '12 - 6:29
Thanku Nagaraj :) It partially worked for me..!!!
Sergey Alexandrovich Kryukov - 8 Mar '13 - 21:24
Correct, a 5. —SA
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  

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 545
1 Maciej Los 270
2 Slacker007 240
3 OriginalGriff 235
4 Aarti Meswania 185
0 Sergey Alexandrovich Kryukov 8,953
1 OriginalGriff 7,134
2 CPallini 3,758
3 Rohan Leuva 3,066
4 Maciej Los 2,528


Advertise | Privacy | Mobile
Web04 | 2.6.130516.1 | Last Updated 4 Oct 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid