Control to stop overwriting an exisitng file

Last post 09-19-2010, 6:34 PM by Eric. 1 replies.
Sort Posts: Previous Next
  •  09-18-2010, 9:24 PM 64078

    Control to stop overwriting an exisitng file

    Is there a control to prevent uploading a file if the file name already exisits
     
    Thanks
     
    Mark
    Filed under:
  •  09-19-2010, 6:34 PM 64085 in reply to 64078

    Re: Control to stop overwriting an exisitng file

    Dear Mark,
     
    Please try the following code:
    <%@ Language="VBScript" %>   
    <!-- #include file="aspuploader/include_aspuploader.asp" -->  
    <html>   
    <head>   
    </head>   
    <body>   
            <form id="form1" method="POST">   
            <%   
                Dim uploader   
                Set uploader=new AspUploader   
                uploader.Name="myuploader"  
                uploader.Render()   
            %>   
            </form>   
    <%  
       If Request.Form("myuploader")&""<>"" Then  
        Dim mvcfile   
        Set mvcfile=uploader.GetUploadedFile(Request.Form("myuploader"))   
           
        Response.Write("<div style='font-family:Fixedsys'>")   
        Response.Write("Uploaded File")   
        Response.Write("<br/><br/>FileName: ")   
        Response.Write(mvcfile.FileName)   
        Response.Write("<br/>FileSize: ")   
        Response.Write(mvcfile.FileSize)   
    '   Response.Write("<br/>FilePath: ")   
    '   Response.Write(mvcfile.FilePath)   
        Response.Write("</div>")  
        targetfilepath= "savefiles/" & mvcfile.FileName
        dim fs   
        Set fs=Server.CreateObject("Scripting.FileSystemObject")   
        if fs.FileExists(server.mappath(targetfilepath)) then   
          'fs.DeleteFile(server.mappath(targetfilepath))
          Response.Write("file has been existing!")
        else
          mvcfile.CopyTo(server.mappath(targetfilepath))  
        end if
    End If    
    %>                    
    </body>   
    </html>
    Thank you for asking
View as RSS news feed in XML