File upload using Classic Asp ,Save It On Server How It possible

File upload using Classic Asp ,Save It On Server How It possible

1
bharat_kumar
2/1/2008 5:24:10 AM
asp.net.free-for-all 9281 articles. 0 followers. Follow

2 Replies
2642 Views

Similar Articles

[PageSpeed] 55
Get it on Google Play
Get it on Apple App Store

aspalliance.com/Michiel/uploadscript.asp 

search.techrepublic.com.com/404.php?page=5100-6371-5031731 upload images

classicasp.aspfaq.com/forms/how-do-i-upload-files-from-the-client-to-the-server.html


Always "Mark an Answer" to all those posts which gave you solution so other people could know the solutions.

Muhammad Adnan
.Net Evangelist
http://weblogs.asp.net/muhammadadnan
http://realfantasy.wordpress.com
0
realfantasy
2/1/2008 6:52:40 AM

Take a new asp page and save it as clsUpload and  remove alla html tags and paste the following code in the page.

 

<%
' ------------------------------------------------------------------------------
' Container of Field Properties
Class clsField
 Public FileName
 Public ContentType
 Public Value
 Public FieldName
 Public Length
 Public BinaryData
End Class
' ------------------------------------------------------------------------------
Class clsUpload
' ------------------------------------------------------------------------------
 Private nFieldCount
 Private oFields()
 Private psFileFullPath
 Private psError
 Private psFileInputName
' ------------------------------------------------------------------------------
 Public Property Get Count()
  Count = nFieldCount
 End Property
' ------------------------------------------------------------------------------
 Public Default Property Get Field(ByRef asFieldName)
  Dim lnLength
  Dim lnIndex
  
  lnLength = UBound(oFields)
  
  If IsNumeric(asFieldName) Then
   If lnLength >= asFieldName And asFieldName > -1 Then
    Set Field = oFields(asFieldName)
   Else
    Set Field = New clsField
   End If
  Else
   For lnIndex = 0 To lnLength
    If LCase(oFields(lnIndex).FieldName) = LCase(asFieldName) Then
     Set Field = oFields(lnIndex)
     Exit Property
    End If
   Next
   Set Field = New clsField
  End If
 End Property
' ------------------------------------------------------------------------------
 Public Function Exists(ByRef avKeyIndex)
  Exists = Not IndexOf(avKeyIndex) = -1
 End Function
' ------------------------------------------------------------------------------
 Public Property Get ValueOf(ByRef avKeyIndex)
  Dim lnIndex
  lnIndex = IndexOf(avKeyIndex)
  if lnIndex = -1 Then Exit Property
  ValueOf = oFields(lnIndex).Value
 End Property
' ------------------------------------------------------------------------------
 Public Property Get FileNameOf(ByRef avKeyIndex)
  Dim lnIndex
  lnIndex = IndexOf(avKeyIndex)
  if lnIndex = -1 Then Exit Property
  FileNameOf = oFields(lnIndex).FileName
 End Property
' ------------------------------------------------------------------------------
 Public Property Get LengthOf(ByRef avKeyIndex)
  Dim lnIndex
  lnIndex = IndexOf(avKeyIndex)
  if lnIndex = -1 Then Exit Property
  LengthOf = oFields(lnIndex).Length
 End Property
' ------------------------------------------------------------------------------
 Public Property Get BinaryDataOf(ByRef avKeyIndex)
  Dim lnIndex
  lnIndex = IndexOf(avKeyIndex)
  if lnIndex = -1 Then Exit Property
  BinaryDataOf = oFields(lnIndex).BinaryData
 End Property
' ------------------------------------------------------------------------------
 Private Function IndexOf(ByVal avKeyIndex)
  Dim lnIndex
  
  If avKeyIndex = "" Then
   IndexOf = -1
  ElseIf IsNumeric(avKeyIndex) Then
   avKeyIndex = CLng(avKeyIndex)
   If nFieldCount > avKeyIndex And avKeyIndex > -1 Then
    IndexOf = avKeyIndex
   Else
    IndexOf = -1
   End If
  Else
   For lnIndex = 0 To nFieldCount - 1
    If LCase(oFields(lnIndex).FieldName) = LCase(avKeyIndex) Then
     IndexOf = lnIndex
     Exit Function
    End If
   Next
   IndexOf = -1
  End If
 End Function
' ------------------------------------------------------------------------------
Public Property Let FileFullPath(sValue)
 psFileFullPath = sValue
End Property
'___________________________________________________________________________________
Public Property Get FileFullPath()
 FileFullPath = psFileFullPath
End Property
' ------------------------------------------------------------------------------
Public Property Let FileInputName(sValue)
 psFileInputName = sValue
End Property
' -------------------- ----------------------------------------------------------
Public Function Save()
 if psFileFullPath <> "" and psFileInputName <> "" then
  'Save to connectionless client side recordset, write to stream,
  'and persist stream.

  'would think you should be able to write directly to
  'stream without recordset, but I could not get that to work

  On error resume next
  binData = o.BinaryDataOf(psFileInputName)
 
  set rs = server.createobject("ADODB.RECORDSET")
  rs.fields.append "FileName", 205, LenB(binData)
  rs.open
  rs.addnew
   rs.fields(0).AppendChunk binData
  
  if err.number = 0 then
   set objStream = Server.CreateObject("ADODB.Stream")
     objStream.Type  = 1
      objStream.Open
    objStream.Write rs.fields("FileName").value
   objStream.SaveToFile psFileFullPath, 2
   objStream.close
   set objStream = Nothing

  ENd if
  rs.close
  set rs = nothing
  psError = Err.Description
else
  psError = "One or more required properties (FileFullPath and/or FileInputName) not set"

  End If


End Function

Public Property Get Error()
 Error = psError
End Property


' ------------------------------------------------------------------------------
 Public Property Get ContentTypeOf(ByRef avKeyIndex)
  Dim lnIndex
  lnIndex = IndexOf(avKeyIndex)
  if lnIndex = -1 Then Exit Property
  ContentTypeOf = oFields(lnIndex).ContentType
 End Property

' ------------------------------------------------------------------------------
 Private Sub Class_Terminate()
  Dim lnIndex
  For lnIndex = 0 To nFieldCount - 1
   Set oFields(0) = Nothing
  Next
 End Sub
' ------------------------------------------------------------------------------
 Private Sub Class_Initialize()
  
  Dim lnBytes    ' Bytes received from the client
  Dim lnByteCount   ' Number of bytes received
  Dim lnStartPosition  ' Position at which content begins
  Dim lnEndPosition  ' Position at which content ends
  
  Dim loDic    ' Contains properties of each
        ' specific field
        ' Local dictionary object(s)
        ' to be appended to class-scope
        ' dictioary object.
        
  Dim lnBoundaryBytes  ' Bytes contained within the current boundary
  Dim lnBoundaryStart  ' Position at wich the current boundary begins
        ' within the lnBytes binary data.
  Dim lnBoundaryEnd  ' Position at wich the current boundary ends
        ' within the lnBytes binary data.
  Dim lnDispositionPosition
  
  Dim lsFieldName   ' Name of the current field being parsed from
        ' Binary Data
  Dim lsFileName   ' Name of the file within the current boundary
  Dim lnFileNamePosition ' Location of file name within current boundary
  Dim loField    ' clsField Object
  Dim lsValue    ' Value of the current field
  Dim lsContentType  ' ContentType of the binary file (MIME Type)
  
  ' Initialize Fields
  nFieldCount = 0
  ReDim oFields(-1)
  
  ' Read the bytes (binary data) into memory 
  lnByteCount = Request.TotalBytes
  lnBytes = Request.BinaryRead(lnByteCount)
  
  'Get the lnBoundaryBytes
  lnStartPosition = 1
  lnEndPosition = InstrB(lnStartPosition, lnBytes, CStrB(vbCr))
  
  If lnEndPosition >= lnStartPosition Then
   lnBoundaryBytes = MidB(lnBytes, lnStartPosition, lnEndPosition - lnStartPosition)
  End If
  
  lnBoundaryStart = InstrB(1, lnBytes, lnBoundaryBytes)
  
  
  ' Loop until the BoundaryBytes begin with "--"
  Do Until (lnBoundaryStart = InstrB(lnBytes, lnBoundaryBytes & CStrB("--")))
  
   ' All data within this boundary is stored within a local dictionary
   ' to be appended to the class-scope dictionary.
   
   ReDim Preserve oFields(nFieldCount)
   nFieldCount = nFieldCount + 1
   
   Set loField = New clsField

   lnDispositionPosition = InstrB(lnBoundaryStart, lnBytes, CStrB("Content-Disposition"))
   
   ' Get an object name
   lnStartPosition = InstrB(lnDispositionPosition, lnBytes, CStrB("name=")) + 6
   lnEndPosition = InstrB(lnStartPosition, lnBytes, CStrB(""""))
   lsFieldName = CStrU(MidB(lnBytes, lnStartPosition, lnEndPosition - lnStartPosition))
   loField.FieldName = lsFieldName
   
   ' Get the location fo the file name.
   lnFileNamePosition = InstrB(lnBoundaryStart, lnBytes, CStrB("filename="))
   lnBoundaryEnd = InstrB(lnEndPosition, lnBytes, lnBoundaryBytes)
   
   'Test if object is a file
   If Not lnFileNamePosition = 0 And lnFileNamePosition < lnBoundaryEnd Then
   
    ' Parse Filename
    lnStartPosition = lnFileNamePosition + 10
    lnEndPosition =  InstrB(lnStartPosition, lnBytes, CStrB(""""))
    lsFileName = CStrU(MidB(lnBytes,lnStartPosition,lnEndPosition-lnStartPosition))
    loField.FileName = lsFileName    
    
    ' Parse Content-Type
    lnStartPosition = InstrB(lnEndPosition,lnBytes,CStrB("Content-Type:")) + 14
    lnEndPosition = InstrB(lnStartPosition,lnBytes,CStrB(vbCr))
    lsContentType = CStrU(MidB(lnBytes,lnStartPosition,lnEndPosition-lnStartPosition))
    loField.ContentType = lsContentType

    ' Parse Content
    lnStartPosition = lnEndPosition + 4
    lnEndPosition = InstrB(lnStartPosition,lnBytes,lnBoundaryBytes)-2
    lsValue = MidB(lnBytes,lnStartPosition,lnEndPosition-lnStartPosition)
    loField.BinaryData = lsValue & CStrB(vbNull)
    loField.Length = LenB(lsValue)
   Else

    ' Parse Content
    lnStartPosition = InstrB(lnDispositionPosition, lnBytes, CStrB(vbCr)) + 4
    lnEndPosition = InstrB(lnStartPosition, lnBytes, lnBoundaryBytes) - 2
    lsValue = CStrU(MidB(lnBytes,lnStartPosition,lnEndPosition-lnStartPosition))
    loField.Value = lsValue
    loField.Length = Len(lsValue)
   End If

   Set oFields(UBound(oFields)) = loField

   'Loop to next object
   lnBoundaryStart = InstrB(lnBoundaryStart + LenB(lnBoundaryBytes), lnBytes, lnBoundaryBytes)
   
   Set loField = Nothing
   
  Loop

 End Sub
' ------------------------------------------------------------------------------
 Private Function CStrU(ByRef psByteString)
  Dim lnLength
  Dim lnPosition
  lnLength = LenB(psByteString)
  For lnPosition = 1 To lnLength
   CStrU = CStrU & Chr(AscB(MidB(psByteString, lnPosition, 1)))
  Next
 End Function
' ------------------------------------------------------------------------------
 Private Function CStrB(ByRef psUnicodeString)
  Dim lnLength
  Dim lnPosition
  lnLength = Len(psUnicodeString)
  For lnPosition = 1 To lnLength
   CStrB = CStrB & ChrB(AscB(Mid(psUnicodeString, lnPosition, 1)))
  Next
 End Function
' ------------------------------------------------------------------------------
End Class
' ------------------------------------------------------------------------------
%>

Now write the following code to the page where you want to upload the file.

<!--#include file="clsUpload.asp"-->

<form name="frmupload" ENCTYPE="multipart/form-data" method= "post">

 <%    
      
      
           
       
       set o = new clsUpload
    
        
       sFileSplit = split(o.FileNameOf("txtFile"), "\")
       sFile = sFileSplit(Ubound(sFileSplit))
       flname = Split(sFile,".")
       
       
        if flname(1) <> "jpg" and flname(1) <> "jpeg" and flname(1) <> "gif" then
        
        
        Response.Redirect("upload_tools.asp?act=invalid")
        
       else
       
         
         o.FileInputName = "txtFile"
         o.FileFullPath = Server.MapPath(".") & "\Uploads\" & sFile
         o.save
        
       
       
       end if
             
     
    %>

</form>

0
bhanupochampally
2/1/2008 6:55:25 AM
Reply:

Similar Artilces:

file uploader save file on server and in database and upload this file on client
hi,i have a file uploader control user can attach files (.rar, .zip, etc) and store file folder and path in database. and another user can click of attach link and can download that file. how can i do this please solve out this problem. you can find your problem solution in this link and you can store the file name in your database server.http://www.aspnettutorials.com/tutorials/network/net-fileupload-aspnet2-csharp.aspxPlease Mark as Answred If This Blog has Helped You.RegardsMitesh Darjihttp://www.indianic.comhttp://www.mitatdotnet.blogspot.com As always there are many ways and which ...

Save a file on the server...using file upload..(Urgent plz)
Hi frinds I am using asp.net fileupload control to uplaod the file from My system.. and store that file on the server disk.. that is on one folder.. can any one tell me what are the things I need to have to stroe my uploaded file on the server.. like server path? servername?.. and can anyone give me a code that to map serverpath..my code is now.. /* fileSaveAsName */ //FileUpload1.SaveAs("C:\\uploads\\" + fileSaveAs); FileUpload1.SaveAs(fileSaveAs); this is here I am stroing in local system in c drive..   Thanks You need Server.MapPath(string path);FileUpload1....

Upload multiple files to the server without using File Upload
I want to upload multiple files to the server without using input type file (File Upload). Is there a way to do this. What I want to do is retrieve multiple file paths (paths are displayed in a user control like text boxes) and upload those files to the server as a bunch. I tried to set the value of the File Upload cotrol (using javascript) but it was not succeed since attributes of the File Upload are readonly. (document.getElementById("fileUploadValue").value = "C:\Test.txt") Is there a way to override the values in File Upload control or is there a way to up...

File Upload to server and save path to uploaded file into a sql database
   I am trying to upload a file to a server and save the path of the uploaded file to a sql 2005 server. I have some code below but im getting the error Object reference not set to an instance of an object. Any help would be greatful. By the way I got this code from these forums and just tweaked them for my website. 1 Dim Fileupload1 As FileUpload = CType(FindControl("FileUpload1"), FileUpload) 2 Dim filePath1 As Label = CType(FindControl("filePath1"), Label) 3 4 If Fileupload1.HasFile Then 5 Try 6 Fileupload1...

without server side scripting, can we upload a file using client side scripting if destination folder and config file settings are known? is it possible?
without server side scripting, can we upload a file using client side scripting if destination folder and config file settings are known? is it possible? avdp211:without server side scripting, can we upload a file using client side scripting if destination folder and config file settings are known? is it possible? I don't think it is possible.You use the the HTML input file control and when you post the request, on the web server you need to read the data and save it to a file, so there has to be some interaction with the server to handle the post request.  Not possible vi...

When I upload a text file from client to server using stream, how can I guarantee that the uploaded text file can be displayed correctly?
When I upload a text file from client to server using stream, how can I guarantee that the uploaded text file can be displayed correctly? A user want to upload a text file from client PC to server (normally it is Windows 2003), but I'm not sure which OS it is in client, maybe it is a english version Windows or chinese Windows (default encoding is GB2312).so the encoding of text file in client maybe is ASCII or GB2312.I think that "StreamReader myRead= new StreamReader(FileUpload1.PostedFile.InputStream,Encoding.Default) will be run in server,so "Encoding.Default" will be the default encodin...

file upload without saving the file on the server
Hi guys I want to let users insert a picture to their profile and I started working on upload subject. with my previous postings I was able to complile a complete script to upload an image to the server and save under a folder. However this isn't working for me. I like to upload the picture without saving it to the server. Is there a way to read the file without saving it ?Thanks where do you want to store them ?if this post unswerd ur question marke it as answer  You can stick the data into a streamDim stream As Stream = fileUpload.PostedFile.InputStream &n...

Save a file to remote server with out the help of file uploader
Hi All,               here i want to save a file to remote server where my file will be in client system...here i don't want to use file uploader control.........In my application we have one function which will save word document to client systems temperory folder and that document again I want to save to server.........  Merry Christmas.............to You All........... Krishna. Could you transfer it via ftp to the folder? I assume you mean that you want the file saved automatically, rather than the user having to u...

Upload files using an IFRAME and save the name of the file to a database
Hello guys, I have a form that saves some data to a table. One of that field is a filename. I am using an iframe with a fileupload control to put the file on the server but I don't know how to pass the name of the file to the container form to save it to my database.  Any ideas? Thanks a lot. David If the IFrame is in the form itself then why cant you directly use the file upload control in the form ?? If you want to learn file uploading you can check it here http://quickstarts.asp.net/QuickStartv20/aspnet/doc/ctrlref/standard/fileupload.aspxNo question is so difficult...

How to File Upload in file server by using web application C#
Currently I am working to upload a csv file  Upload in file server (not on webserver) getting error , I map Y drive to our file server. (y=\\fileserver\load\) Could not find a part of the path 'Y:\LeadsUpload\errorfixsales.xls'. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.IO.DirectoryNotFoundException: Could not find a part of the path 'Y:\LeadsUpload\errorfixsales.xls'.   FileUpLoad1...

Using EA Server and PB NVO for saving files in EA Server itself.
Hi, My design is: 1. Submit information to the component B from webpage A. 2. component B generates a file (select blob and write the file) and save it in somewhere in the EA server. 3. webpage A redirect to webpage C and sends information to webpage C which contains file link information of the file which generates be component B. 4. user click on the file link on webpage C and the file is sent to the user. webpage A and C is written in jsp format component B is a PB NVO. Environment: EA Server 5.2, Jaguar on JDK 1.3 and PB 10.2 build 7516 Is this design workable in EA serv...

File Upload on file server not on webserver, by using web application C#
I know how to upload files on webserver, but when trying to upload a file on different machine getting  error I am trying with FileUpLoad1.SaveAs(@"\\enterprise\LeadsUpload" + FileUpLoad1.FileName);getting error Logon failure: unknown user name or bad password.  please help.DostMy website The server services authentication credentials don't have access to your unc path. Why not create a virtual path under you webserver that points to the unc provide the necessary credentials and then write to that path versus the unc path.  Which would also b...

How to identify the original file type and restrict the file uploading while using file upload control
 Hi asp.net , I am uploading a file using FileUpload control in asp.net using vb.net.I wrote the code to upload only PDF files. the user can change the extension and change to PDF . I have to check is the file original PDF or not then i have to upload the PDF files only . How to do this ??  Hi, Check the file Mime type for "application/pdf" by looking at the:  FileUpload1.PostedFile.ContentType RegardsSmcoxonNo Gem is ever polished without some friction. Hi smcoxon , Thanks For Replying ,But i found that there is no use using PostedFil...

File Upload: use file system + "sync" with sql server db
I explored the fileupload control a bit, and find it wonderful. I also stumbled upon this website, http://imar.spaanjaars.com/QuickDocId.aspx?quickdoc=414, and read a few (and tried the free demo code that comes with the article, in VB :) ).now, although storing files in a database seem to make "connecting" the uploaded files to a record easier, i think one downside of this is limited SQL Server space. Most of the time, hosts have a bigger "disk space" than its sql db space. what would be the best approach to "Syncronize" your sql server database with the uploaded files in a folder? lik...

Upload file from remote Computer using File Upload
Hi,     How to upload file from remote computer. Can i browse it thruough the File Upload control ?    Please help?     RamarjunK:Hi,     How to upload file from remote computer. Can i browse it thruough the File Upload control ?    Please help?  you can. when the file open dialog box comes, choose my network places, select the corrosponging share, specify the credentials.  then choose the file.you haven't do any thing special, coding is same .Give a man a fish and you feed him for a day. Teach a man to fish a...

Web resources about - File upload using Classic Asp ,Save It On Server How It possible - asp.net.free-for-all

Ted Cruz: As Gutless As Jeb Bush
(See update below.) Did you hear? Ted Cruz finally criticized Donald Trump! The New York Times says so, therefore it must be true ... right? ...

Historic climate agreement adopted in Paris aims to push global economy away from fossil fuels
PARIS — After more than two decades of negotiations, diplomats finally succeeded in passing a sweeping global climate change accord that applies ...

LOL: ‘Star Wars: The Force Awakens’ Gets a New Holiday Special
Any Star Wars fan can tell you that even though plenty of people don’t like the prequels, the worst thing to come out of the sci-fi saga is undoubtedly ...

ISIS Printing Fake Syrian Passports: Have Any Been Used To Sneak Into The U.S.?
ISIS is in possession of two machines that can print fake Syrian passports, and at least some of them may have been used to sneak into the United ...

Elon Musk Backs $1 Billion Artificial Intelligence Research Group
Elon Musk and other technology giants have chipped in $1 billion toward researching artificial intelligence to “benefit humanity,” the business ...

Authorities: Fire at Southern California mosque was arson
CBS News Authorities: Fire at Southern California mosque was arson Sacramento Bee A Southern California mosque was damaged in a fire that ...

Man Jailed in 2 Miss. Police Slayings Dies; Autopsy Planned
Autopsy planned in death of inmate charged in slaying of 2 Mississippi police officers

The Latest: California Shooting Victim Mourned
The Latest: Man who shielded co-worker during California shooting is mourned

Saudi Arabia's Women Vote For the First Time in History
Women in Saudi Arabia went to the polls this morning after it was confirmed earlier this year that they would finally be allowed to vote. Saudi ...

Is Justin Bieber’s New Wings Tattoo A Response To Selena Gomez’s Bizarrely Petty Shade?
Justin Bieber has a brand new tattoo. But his romantic life seems to be focused on an old love. More on that below. Yes. The Biebs’ never-ever-sated ...

Resources last updated: 12/12/2015 6:50:44 PM