Avatar of vis-66
vis-66
 asked on

HELP - Need a code Buddy

I am new to asp and sql. I have a job to do and with limited understanding of the way I need to gain the logic. I have and old upload form using aspUpload and now moving to FreeAspUpload. The form collects information for a small classifieds, form data written to sql database, display information drawn from DB, file attachments written to web folder according to date of upload. If you think you are able to assist me - let me know.
ASPWeb Languages and StandardsMicrosoft SQL Server

Avatar of undefined
Last Comment
Surone1

8/22/2022 - Mon
Surone1

i assume you are new to the site? think of us as a bunch of code buddies. only you need to ask the right questions. or supply us with more information. (the thing you have trouble understanding, the lines in your code dealing with aspupload that need to be changed, or the lines where you get errors )  it may not be wise to post too much of your code for security reasons.
vis-66

ASKER
fileupload-code.txtform-code.txt Thanks.

I have attached the files that are involved.

There is a regular form with ordinary fields.

There is a upload function page and a freeASP Upload file.

I need the Attachments to be uploaded into a folder which is name by the current date.

AI have checked errors and get as far as outputing the string I am lookiing for but I cannot upload. I am missing something.

Go easy on me - I am new to this

(I have commented out the sql stuff for the moment - I will worry abou that later)
freeaspupload.txt
Surone1

i just installed ASP.NET and by the looks of it this is classic asp code. so i will have to install that if i can. but it's late for me now. so i'll get back on this tomorrow if nobody else jumps in.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
Surone1

ok i  just got things working on my end after playing around with the testupload.asp they include in the zip file :
i did create a directory "c:\testupload" and gave write permission to IUSR

then i took the lines of code we needed from the example and pasted that into the source:

<%@ Language=VBScript %>
<%

'On Error Resume Next

Response.Expires = -1
Server.ScriptTimeout = 600
' All communication must be in UTF-8, including the response back from the request
Session.CodePage  = 65001

%>
<!--#include file="./freeaspupload.asp"-->
<%
      
   
          Dim uploadsDirVar
   
    uploadsDirVar = "c:\testupload"



    function SaveFiles
    Dim Upload, fileName, fileSize, ks, i, fileKey

    Set Upload = New FreeASPUpload
    Upload.Save(uploadsDirVar)

      ' If something fails inside the script, but the exception is handled
      If Err.Number<>0 then Exit function

    SaveFiles = ""
    ks = Upload.UploadedFiles.keys
    if (UBound(ks) <> -1) then
        SaveFiles = "<B>Files uploaded:</B> "
        for each fileKey in Upload.UploadedFiles.keys
            SaveFiles = SaveFiles & Upload.UploadedFiles(fileKey).FileName & " (" & Upload.UploadedFiles(fileKey).Length & "B) "
        next
    else
        SaveFiles = "No file selected for upload or the file name specified in the upload form does not correspond to a valid file in the system."
    end if
      SaveFiles = SaveFiles & "<br>Enter a number = " & Upload.Form("enter_a_number") & "<br>"
      SaveFiles = SaveFiles & "Checkbox values = " & Upload.Form("checkbox_values") & "<br>"
      SaveFiles = SaveFiles & "List values = " & Upload.Form("list_values") & "<br>"
      SaveFiles = SaveFiles & "Text area = " & Upload.Form("t_area") & "<br>"
end function
   
   
   
          response.write SaveFiles()
    response.write "<br>end<br>"
    response.end
'this uploaded the file without any problems
vis-66

ASKER
I am able to upload a file as well - this is what I need the code to do:

I have a date field - I need the date field to become the name of folder to contain each uploaded attachment - I think I am missing some code to enable me to create the folder object. Did you see my attachments?

Thanks in advance
Surone1

as far as i can tell the upload directory would need to exist for this script to work., so you would need a way to create the directory before setting the uploadsDirVar to it.

this could help?
http://www.devguru.com/technologies/vbscript/quickref/filesystemobject_createfolder.html
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
vis-66

ASKER
I need to create a directory on the fly - is there no way?

The previous code that was used for this project used the date as a string which then became the folder name. If there was an existing folder a folder would not be generated but the attachment would then be uploaded to the existing folder. If a folder was needed the date   would be used as the new generated folders name and the attachment then uploaded.

What are my chances in adapting the code I have attached?
Surone1

pretty good?
have a look at the link above, it contains an example of how to create a directory. you probably want to fix the types of the variables before pasting it in your code since your code has "option explicit" turned on.
Surone1

try this as a seperate page first.

<%

dim filesys, newfolder
post_date = DatePart("yyyy",Date)& DatePart("m",Date) & DatePart("d",Date)
uploadsDirVar = "/staff/portal/classifieds/attachments/" + post_date

set filesys=CreateObject("Scripting.FileSystemObject")
If Not filesys.FolderExists(uploadsDirVar) Then
   Set newfolder = filesys.CreateFolder(uploadsDirVar)
   Response.Write("A new folder has been created at: " & uploadsDirVar)
End If

%>
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
vis-66

ASKER
currently just without a development platform. I do develop some asp.net in MS VS 10 but the classic asp just handcoded without a platform in WYSIWYG editor (Adobe DW)
vis-66

ASKER
I have tried the attached code - this is it! I am getting an internal 500 error (doesnt tell me much)
When I break the code in the middle I have the correct output but it will not allow me to create the file.

<%

dim filesys, newfolder
post_date = DatePart("yyyy",Date)& DatePart("m",Date) & DatePart("d",Date)
uploadsDirVar = "/staff/portal/classifieds/attachments/" + post_date

   'Response.Write("A new folder has been created at: " & uploadsDirVar)
  ' response.end()

set filesys=CreateObject("Scripting.FileSystemObject")
If Not filesys.FolderExists(uploadsDirVar) Then
   Set newfolder = filesys.CreateFolder(uploadsDirVar)
   Response.Write("A new folder has been created at: " & uploadsDirVar)
End If

%>
Surone1

<%
on error goto hell
dim filesys, newfolder
post_date = DatePart("yyyy",Date)& DatePart("m",Date) & DatePart("d",Date)
uploadsDirVar = "/staff/portal/classifieds/attachments/" + post_date

   'Response.Write("A new folder has been created at: " & uploadsDirVar)
  ' response.end()

set filesys=CreateObject("Scripting.FileSystemObject")
If Not filesys.FolderExists(uploadsDirVar) Then
   Set newfolder = filesys.CreateFolder(uploadsDirVar)
   Response.Write("A new folder has been created at: " & uploadsDirVar)
End If
response.end
hell:
response.write err.number & " - " &  err.description
%>
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
vis-66

ASKER
No luck - only an internall 500 error - no error or error number
ASKER CERTIFIED SOLUTION
Surone1

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
vis-66

ASKER
Changed up my code
Found out what one of my problem were- hadnt fixed one of my variables (snewfolder) adn hadnt mapped my variable to the server.

Thanks everyone. I will be back with some new problems as I move towards entering this data now to the sql server - more fun

post_date = DatePart("yyyy",Date)& DatePart("m",Date) & DatePart("d",Date)
uploadsDirVar = "/staff/portal/classifieds/attachments/" + post_date

snewfolder = server.mapPath(uploadsDirVar)

' Response.Write(snewfolder)
'   response.end()

set filesys=CreateObject("Scripting.FileSystemObject")
If Not filesys.FolderExists(snewfolder) Then
'response.Write("Folder doesn't exists")
'      response.end()
   Set newfolder = filesys.CreateFolder(snewfolder)
'   Response.Write("A new folder has been created at: " & snewfolder)
'   response.end()
Else
'      response.Write("Folder exists")
'      response.end()
End If
vis-66

ASKER
I have one final issue with my code - I have a database with a time stamp field. I have a variable named today which is equals 'now'. I know my date/time string is incorrect but I am not sure how I need to format it

Any answers?
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Surone1

that would actually be a new question i guess , but i can tell you you probably want to use  the format function for it :-)
http://www.techonthenet.com/access/functions/date/format.php
Surone1

sorry i assumed asp has the format function. turns out it doesnt :-(
asp has formatdatetime. which is rather limited
http://www.powerasp.net/content/new/formating-date-and-time.asp
vis-66

ASKER
apologies for entering a different question. I will create a new question next time.

the format for my sql database is set to US (unfortunately)

1900-01-01 00:00:00.000

my output

insert into staff_page_classifieds (title, body, name, phone, email, type, closed, owner, post_date, time_stamp, attachment) values ('TEST','test','vee','11234535','veej@live.com.au','2','','jacobsv','2012102','2/10/2012','/staff/portal/classifieds/attachments/2012102/adobe-icons.jpg')

I am not sure how to set the string for this output
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Surone1

db_date = DatePart("dd",Date) & "/" & DatePart("mm",Date) & "/" & DatePart("yyyy",Date)
or
db_date = DatePart("mm",Date) & "/" & DatePart("dd",Date) & "/" & DatePart("yyyy",Date)
vis-66

ASKER
no - not working

I have include hours, minutes seconds as well

today=DatePart("yyyy",Date) & "-" & DatePart("mm",Date) & "-" & DatePart("dd",Date)& DatePart("hh",Date)&":"& DatePart("mm",Date)&":"& DatePart("ss",Date)
vis-66

ASKER
I've requested that this question be closed as follows:

Accepted answer: 0 points for vis-66's comment #a38449502

for the following reason:

This solution was not straight forward. The server map path was needed to create the new folder according to the aspfreeupload file.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
vis-66

ASKER
Creating a directory on the fly with aspfreeupload using a date field as the folder name so folders and items may be ordered by date in its final transending into a Database
Surone1

https://www.experts-exchange.com/questions/27878327/HELP-Need-a-code-Buddy.html?anchorAnswerId=38449502#a38449502

the thanks suggests the asker was helped somehow.
---
back to the second question here DatePart("mm",Date) will give you the month. not minutes.
us DatePart("nn",Date) for minutes
Surone1

sorry pressed submit instead of object in the above post.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Surone1

there is also no space between the year and hour parts in your code.
vis-66

ASKER
Yes I think you are right JARmod101...I will assign to Surone1.

I found I needed a collective of info to get the code working but this was the most helpful.

Thanks everyone - most appreciated
vis-66

ASKER
I've requested that this question be closed as follows:

Accepted answer: 0 points for vis-66's comment #a38453252

for the following reason:

Date formatting has made the difference
Your help has saved me hundreds of hours of internet surfing.
fblack61
Surone1

Surone1