[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

uploading of file to the server

Posted on 2003-10-28
8
Medium Priority
?
728 Views
Last Modified: 2012-06-27
I have tried this code and it works fine.

asp.net
Select file to upload: <input id="uploadedFile" type="file" runat="server" NAME="uploadedFile">

vb.net
                Dim savePath As String = "C:\temp\"
                Dim postedFile = uploadedFile.PostedFile
                Dim filename As String = Path.GetFileName(postedFile.FileName)
                Dim contentType As String = postedFile.ContentType
                Dim contentLength As Integer = postedFile.ContentLength

                postedFile.SaveAs(savePath & filename)

but i will like to have a check such that when the user uploads a file to the temp directory. if there is already a file with the same name in the directory, prompt the user whether the user wants to overwrite the file. Also prompt the user when the file choosen is not found instead of creating an empty file in the server side.
0
Comment
Question by:adomsg
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 4

Expert Comment

by:meet_zorrer
ID: 9632748
Hi !
There are two parts of your question:

Part 1:  [ ... check such that when the user uploads a file to the temp directory. if there is already a file with the same name in the directory... ]

Answer:
           Before the line in your code [... postedFile.SaveAs(savePath & filename)  ...], you can check for the existence of the file on the server in your uploading temp directory, and here is the code...
          Dim bFlag as Boolean = False
          If System.IO.File.Exists(savePath & filename) then
                  bFlag = True
          End if
          ' Now as the bFlag will be set to true if file already exits in the temp upload server
          ' directory. So you can now code as to your whish, e.g if there is some lblError in your
          ' page, that you set it to Visible=False, then you can Make it visible and show the messge
          ' to the User/Client. or you can Visible as Checkbox to allow the user to Confirm the file
          ' Upload and Overwrite

          If bFlag then
                 lblError.Visible = True
                 lblError.Text = "Server Side File All Ready Exits"
                 chkOverwrite.Visible = True
                 chkOverWrite.Text = "Confirm Overwrite ?"
         
          Else 'just save the uploaded file to the temp server directory
                postedFile.SaveAs(savePath & filename)
          End if

Part 2:  [ Also prompt the user when the file choosen is not found instead of creating an empty file in the server side. ]

Answer:
           Kindly Explain More ...what i have understand is this, you want to give the user error message that "Server side file does not exits so you (User) cannot upload file", meaning that you only want to upload the file when the file already exits, also confirm the Uploading by User from your Part1 of your question. so if your meaning is this then same as above my code will help you to find out the solution of this prob, here is how...

           If bFlag = False then 'as file is not found on the server
                    lblError.Visible = True
                    lblError.Text = "Server side file does not exits so you cannot create new file!"
           Else 'just overwrite the file that already exits on server
                  postedFile.SaveAs(savePath & filename)
           End if
0
 
LVL 2

Author Comment

by:adomsg
ID: 9632837
sorry about the second ques. What i meant is that i want 2 prompt the user if the file path in the uploadedFile input box does not point to a file in the client side.

Thanks
0
 
LVL 2

Author Comment

by:adomsg
ID: 9638128
for the part 1 answer, hw do i show a message box that will ask the user whether he want 2 overwrite or not? Thanks
0
Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

 
LVL 4

Expert Comment

by:meet_zorrer
ID: 9638534
Hi Again!

Well your requirment for the part 1 and part 2 both are cleard to me now, but there is one problem, the total points of your question are lacking 100, i mean this question should have 155 than to just 55 points, if you increase the points, then i can move on to furthur answer, till then...

bye bye amego....

PS:
I am felling greedy now  }:-$
0
 
LVL 2

Author Comment

by:adomsg
ID: 9638680
sorry, but the most i can give is 100, cos i need the remaining points to post another question once this question is out of the way.

Really hope u can help.

PS
Greed is the root of all evil.
0
 
LVL 4

Expert Comment

by:meet_zorrer
ID: 9640369
so increase the points man !
0
 
LVL 2

Author Comment

by:adomsg
ID: 9640622
ok.
0
 
LVL 2

Accepted Solution

by:
adomsg earned 0 total points
ID: 9655804
I v found the solution to the second question. That is
if uploadedFile.PostedFile.ContentLength <> 0 Then
    //print file not found.
end if

for the first question. To prompt the user, must use JavaScript
0

Featured Post

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question