Solved

Upload a file using a ASP page

Posted on 2006-10-31
18
828 Views
Last Modified: 2010-05-18
Hi there,
I have a page that takes the input form the user and allows then to save a file to a folder in the root directory. but for some reason is not working properly i'm using a file i got somewhere called clsField.asp along with my page but what i think is falling is the writtting the new file to  the folder.
Here is the code for my page:
 <%@language=VBScript%>
<!--#include file="../includes/security.asp"-->
<!--   #include file="../includes/dbConnect.asp"  -->
<!--#INCLUDE FILE="../clsUpload.asp"-->
<%
Dim objUpload
Dim strFileName
Dim objConn
Dim objRs
Dim lngFileID

' Instantiate Upload Class
Set objUpload = New clsUpload

' Grab the file name
strFileName = objUpload.Fields("pdf").FileName

Set objConn = Server.CreateObject("ADODB.Connection")
Set objRs = Server.CreateObject("ADODB.Recordset")


objConn.open sConnect


'objConn.Open sConnect

objRs.Open "Releasses", objConn, 3, 3

objRs.AddNew


objRs.Fields("ReleaseName").Value =      objUpload.Fields("ReleaseName").Value
objRs.Fields("PostOnline").Value =       objUpload.Fields("PostOnline").Value

If objUpload.Fields("PostOnline").Value = "True" Then
      objRs.Fields("PostOnline").Value = True
Else
      objRs.Fields("PostOnline").Value = False
End If


objRs.Fields("pdfname").Value = strFileName

' Compile path to save file to
strPath = Server.MapPath("\ParkRec\pdf") & "\" & strFileName


' Save the binary data to the file system
objUpload("pdf").SaveAs strPath

objRs.Update
objRs.Close

Set objRs = Nothing
Set objConn = Nothing
'*********Set objUpload = Nothing

Response.Redirect("NewReleaseDisplay.asp.asp?ri=" & objUpload.Fields("ReleaseName").Value)
%>

and the part where i'm getting the error on the clsField is as follows:

            ' Save the binary data to file system
            '      Overwrites file if previously exists!
            Call lobjStream.SaveToFile(pstrFileName, adSaveCreateOverWrite)

the error i'm getting is:
Error Type:
ADODB.Stream (0x800A0BBC)
Write to file failed.
/ParkRec/clsField.asp, line 178

Can anyone help me resolving this issue?
Thanks
0
Comment
Question by:jsctechy
[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
  • 11
  • 6
18 Comments
 
LVL 20

Expert Comment

by:Gawai
ID: 17841785
make sure you have set read/write permission on that folder
0
 
LVL 58

Expert Comment

by:Gary
ID: 17841872
The last place you should allow uploads to is the root directory - anyone could upload a new index page and bang goes your site, you should use a sub folder that is for uploads only.
0
 
LVL 1

Author Comment

by:jsctechy
ID: 17841887
no i do have a different folder in the root, sorry i did not specified that my root looks like this:
C:\Inetpub\wwwroot\ParkRec\PressRelease\pdf and here is where the files that are upload will be store
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 1

Author Comment

by:jsctechy
ID: 17841921
>>make sure you have set read/write permission on that folder
i did that already and still have a the same error

any suggestion?
0
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
ID: 17842142
Replace this...

strPath = Server.MapPath("\ParkRec\pdf") & "\" & strFileName


With...

strPath = "C:\Inetpub\wwwroot\ParkRec\PressRelease\pdf\" & strFileName
0
 
LVL 1

Author Comment

by:jsctechy
ID: 17842165
Error Type:
Microsoft VBScript compilation (0x800A0401)
Expected end of statement
/ParkRec/PressRelease/NewReleasePost.asp, line 42, column 66
strPath = "C:\Inetpub\wwwroot\ParkRec\PressRelease<WBR>\pdf\" &amp; strFileName
-----------------------------------------------------------------^
0
 
LVL 58

Expert Comment

by:Gary
ID: 17842204
Think something went wrong there with copying, when copying text from this page paste to notepad first to get rid of formatting if you're using FP or similar
0
 
LVL 1

Author Comment

by:jsctechy
ID: 17842242
yeah  i just notice that thanks.

Now for testing purposes this is great because i found the folder and store the file there, but when i'm ready to deploy my application it will save somewhere el rather than the C:\Inetpub\wwwroot\ParkRec\PressRelease\pdf\ how can i make the path change instead of having to write the exact location of where i want it
My guess here is the previous person who code this page that i took as a reference uses:
strPath = Server.MapPath("\ParkRec\pdf") & "\" & strFileName
where somewhere Server.MapPath is define with the exact location how can i use something like that?
0
 
LVL 58

Expert Comment

by:Gary
ID: 17842278
But is it working now?
Once you deploy you can easily find out the exact path using a response.write server.mappath("...") then hardcode that into your code.
0
 
LVL 1

Author Comment

by:jsctechy
ID: 17842288
oh ok
not is not working it wites it to the database but it does not save the file to the folder because it triggers an error that i have specified
0
 
LVL 58

Expert Comment

by:Gary
ID: 17842361
And you have definitely given the IUSR_machinename Read/Write permissions on that folder?
0
 
LVL 1

Author Comment

by:jsctechy
ID: 17842478
yes i have done that
0
 
LVL 1

Author Comment

by:jsctechy
ID: 17842581
ok i got it i was looking at the wrong ASP file so that was causing the error
Thanks
0
 
LVL 1

Author Comment

by:jsctechy
ID: 17842618
i just have a question now that the file is getting store in the folder my page has and if statement that if the name already exist to show something else but for some reason is not doing it. Is there a way that you can take a look of it?

<%@language=VBScript%>
<!--#include file="../includes/security.asp"-->
<!--   #include file="../includes/dbConnect.asp"  -->
<html>
<head>
<title>Administration</title>

 
</head>
<%
ReleaseID = Request.QueryString("ri")


'login to the database for details see dbConnect.asp
set conn = server.CreateObject("ADODB.Connection")

conn.open sConnect

mySQL = "select * from Releasses where ReleaseName = '" & ReleaseID & "'"

response.write mySQL
Response.end

set rstemp = conn.Execute(mySQL)
 
if not rstemp.EOF then


%>
<body bgcolor="#ADCED3" text="#000000"  leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">

<!--#include file="../includes/headerinc.htm"-->

<table width="100%" border="0" cellspacing="0" cellpadding="0" >
<tr>
    <td align="center" valign=top >
    <table width="760" border="0" cellspacing="0" cellpadding="0" bgcolor="#ffffff">
    <tr>
      <td width="760" align=center>
          <img src="images/viewupdatedeletereleases.jpg" alt="View New Release" width="307" height="64">
      </td>
         </tr>
         </table>
         </td>
</tr>    
   
<tr>
<td align=center  valign="top" >

    <TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 width="760" bgcolor="#FFFFFF">
    <tr>
       <td COLSPAN=3>&nbsp;</td></tr>
    </tr>
    <tr>
       <td COLSPAN=3>&nbsp;</td></tr>
    </tr>
    <TR>
     <TD WIDTH="30"  ALIGN=LEFT>&nbsp;</TD>
     <td width="700" valign=top align=center >

     <form action="NewReleaseDisplay.asp" method="post" name="table1"  >

    <input type="hidden" name="tex" value=5>

    <font face="Verdana, Arial, Helvetica" Size="2">
    <table width="576" border="0" cellspacing="0" cellpadding="2" bgcolor="#FFFFFF" bordercolor="#FFFFFF">
    <tr>
     <td align=center>
      <table width="400" border="0" cellspacing="2" cellpadding="2">
      <tr>
         <td bgcolor="#F0E7B0" width="120" align="right"><font face="Verdana, Arial, Helvetica" Size="2">
         Release Description:</font></td>
         <td bgcolor="#ADCED3" width="260"><font face="Verdana, Arial, Helvetica" Size="2"><% Response.Write rstemp("ReleaseName") %></font></td>
      </tr>
       <tr>
         <td bgcolor="#F0E7B0" width="120" align="right"><font size="2">Post Online</font><font face="Verdana, Arial, Helvetica" Size="2">:</font></td>
         <td bgcolor="#ADCED3" width="260"><font face="Verdana, Arial, Helvetica" Size="2"><% Response.Write rstemp("PostOnline")%></font></td>
      </tr>
      <tr>
           <font face="Verdana, Arial, Helvetica" Size="2">
         <td bgcolor="#F0E7B0" width="120" align="right"><font face="Verdana, Arial, Helvetica" Size="2">
         PDF Name:</font></td>
         <td bgcolor="#ADCED3" width="260"><font face="Verdana, Arial, Helvetica" Size="2"><a href="../PressRelease/pdf/<% Response.Write rstemp("pdfname")%>"><% Response.Write rstemp("pdfname")%></a></font></td>
  </font>
      </tr>
      <tr><td colspan=2>&nbsp;</td></tr>
      <tr><td colspan=2>&nbsp;</td></tr>
      <tr>
       <td colspan=2><font face="Verdana, Arial, Helvetica" Size="2">
       <a href="PressReleasses.asp">Back to Add a New Release</a></font></td>
      </tr>
      <tr><td colspan=2>&nbsp;</td></tr>
      <tr>
       <td colspan=2><font face="Verdana, Arial, Helvetica" Size="2">
                <a href="../user.asp">Back to Administration Menu</a>
 
       </font></td>
      </tr>
      </table>
     </td>
    </tr>
    </table>


  </font>
</form>



<% else %>
<body bgcolor="#ADCED3" text="#000000"  leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">

<table width="100%" border="0" cellspacing="0" cellpadding="0" >
<tr>
    <td align="center" valign=top >
    <table width="760" border="0" cellspacing="0" cellpadding="0" bgcolor="#ffffff">
    <tr>
      <td width="760" align=center>
          <img src="images/viewupdatedeletereleases.jpg" alt="View New Release" width="307" height="64">
      </td>
         </tr>
         </table>
         </td>
</tr>    
   
<tr>
<td align=center  valign="top" >

    <TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 width="760" bgcolor="#FFFFFF">
    <tr>
       <td COLSPAN=3>&nbsp;</td></tr>
    </tr>
    <tr>
       <td COLSPAN=3>&nbsp;</td></tr>
    </tr>
    <TR>
     <TD WIDTH="30"  ALIGN=LEFT>&nbsp;</TD>
     <td width="700" valign=top align=center >

    <form action="NewReleaseDisplay.asp" method="post" name="table2"  >

    <input type="hidden" name="tex" value=5>

    <font face="Verdana, Arial, Helvetica" size="2">
   <table width="576" border="0" cellspacing="0" cellpadding="2" >
    <tr>
      <td width="576" align=center>
      <table width="400" border="0" cellspacing="0" cellpadding="2">
      <tr>
         <td><font face="Verdana, Arial, Helvetica" size="2">The Release entered is already taken.<BR>
            Please try again.<BR>
            </td>
         </tr>
         <tr><td>&nbsp;</td></tr>
      <tr><td>&nbsp;</td></tr>
      <tr>
         <td><font face="Verdana, Arial, Helvetica" Size="2">
         <a href="PressReleasses.asp">Back to Add a </a></font>
         <font size="2"><a href="PressReleasses.asp">New Release</a></font></td>
      </tr>
         <tr><td>&nbsp;</td></tr>
      <tr>
         <td><font face="Verdana, Arial, Helvetica" Size="2">
                <a href="../user.asp">Back to Administration Menu</a>
</font></td>
       </tr>
      </table>
      </td>
     </tr>
     </table>
  </font>
</form>
<%end if%>

    </TD>
    <TD WIDTH="30"  ALIGN=LEFT>&nbsp;</TD>
</TR>
<TR>
    <TD WIDTH="30"  ALIGN=LEFT>&nbsp;</TD>
    <TD WIDTH="700" align=left>&nbsp;</td>
    <TD WIDTH="30"  ALIGN=LEFT>&nbsp;</TD>
</tr>
</table>

</td>
</tr>

    <tr>
    <td>
     <div align="center">
      <center>
      <table border="0" cellpadding="0" cellspacing="0" width="760" >
        <tr>
          <td >
                <!--#include file="../includes/footerinc.htm"-->
          </td>
        </tr>
      </table>
      </center>
    </div>
    </td>
    </tr>
</table>

 
 
</body>
</html>

0
 
LVL 58

Expert Comment

by:Gary
ID: 17842676
Don't quite follow what you mean? When saving the file?
0
 
LVL 1

Author Comment

by:jsctechy
ID: 17842680
if i create a new release with the same name and i attached a pdf file with it it will not show that pdf instead of i will show the first one that was store prior my latest addition is there a way to fix this? or i need to open a new question?
0
 
LVL 1

Author Comment

by:jsctechy
ID: 17842786
i think my error is here: this is my NewReleasePost.asp page, in this file i wil take the inputs from the user and i will store to a SQL database, so i'm grabing the file by the name but in the database the name can be the same. In the database i have a field called ReleaseID where incremnets anytime a new release is added if instead of passing this attribute to my next page instead of the release name it will be great because that field is unique on the table .

here the code for the asp page:

<%@language=VBScript%>
<!--#include file="../includes/security.asp"-->
<!--   #include file="../includes/dbConnect.asp"  -->
<!--#INCLUDE FILE="../clsUpload.asp"-->
<%
Dim objUpload
Dim strFileName
Dim objConn
Dim objRs
Dim lngFileID

' Instantiate Upload Class
Set objUpload = New clsUpload

' Grab the file name
strFileName = objUpload.Fields("pdf").FileName

Set objConn = Server.CreateObject("ADODB.Connection")
Set objRs = Server.CreateObject("ADODB.Recordset")


objConn.open sConnect


objRs.Open "Releasses", objConn, 3, 3

objRs.AddNew

objRs.Fields("ReleaseName").Value =      objUpload.Fields("ReleaseName").Value
objRs.Fields("PostOnline").Value =       objUpload.Fields("PostOnline").Value

If objUpload.Fields("PostOnline").Value = "True" Then
      objRs.Fields("PostOnline").Value = True
Else
      objRs.Fields("PostOnline").Value = False
End If

objRs.Fields("pdfname").Value = strFileName

' Compile path to save file to
strPath = "C:\Inetpub\wwwroot\ParkRec\PressRelease\pdf\" & strFileName
'strPath = Server.MapPath("\ParkRec\pdf") & "\" & strFileName


' Save the binary data to the file system
objUpload("pdf").SaveAs strPath

objRs.Update
objRs.Close

Set objRs = Nothing
Set objConn = Nothing
'*********Set objUpload = Nothing

Response.Redirect("NewReleaseDisplay.asp?ri=" & objUpload.Fields("ReleaseName").Value)
%>

see how my last line will redirect the user ro the a new ASP page base on the ReleaseName store in the DB in line before that.
Is there a way to get the releaseID from the DB and parse instead of releaseName?
Thanks
0
 
LVL 1

Author Comment

by:jsctechy
ID: 17843192
i already figure it out thanks ;-)
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
File download script VBSCRIPT fail on download PPT files 2 75
VBScript on Html 15 64
Time comparison asp 1 26
VB script help 23 48
I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

740 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