1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Print all files within a folder by using ASP (VBScript)

Discussion in 'C#' started by gray d' newbie, Jul 27, 2008.

  1. #1
    Greetings All,

    I'm quite fresh with ASP and I'm not very good in scripting. Recently I was assigned to develop a function in a web system that developed in ASP, and the function sounds something like this: A printing function that capable to print all files that located in a specific folder.

    I've tried several codes in VB, but they are not working at all.

    Thank you very much for your time.

    Best Regards,
    Gray d' Newbie
     
    gray d' newbie, Jul 27, 2008 IP
  2. dylanj

    dylanj Peon

    Messages:
    173
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    0
    #2
    
    <%
    Dim fs, fo, x
    Set fs = Server.CreateObject("Scripting.FileSystemObject")
    Set fo = fs.GetFolder("c:\inetpub\yourfolder\")
    For Each x In fo.Files
      Response.Write(x.Name & "<br />")
    Next
    Set fo = Nothing
    Set fs = Nothing
    %>
    
    Code (markup):
    That what you're looking for?

    Oh, and make sure the IUSR account has read access to the specified folder.
     
    dylanj, Jul 28, 2008 IP
  3. gray d' newbie

    gray d' newbie Peon

    Messages:
    15
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks in advance. I will try on the code. I'm just curious but the code you stated doesn't consists any function on printing. How am I supposed to print them? Thank you.
     
    gray d' newbie, Jul 28, 2008 IP
  4. ludwig

    ludwig Notable Member

    Messages:
    2,253
    Likes Received:
    66
    Best Answers:
    0
    Trophy Points:
    225
    #4
    lol, the code he showd write in the browser window, then you go to FILE > PRINT from your browser windows
     
    ludwig, Jul 28, 2008 IP
  5. gray d' newbie

    gray d' newbie Peon

    Messages:
    15
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Yup. I tried on the code. It displays all the file that I have in the browser for instance:

    a.doc
    b.doc

    but if i go to FILE > PRINT, it will print the browser content right, it won't print the file content. Which means that my output will be a piece of paper that has all the files name written on it. :)

    Actually I'm looking for codes that can print the contents of the all the files that located in a folder.

    Thank you very much.
     
    gray d' newbie, Jul 28, 2008 IP
  6. ludwig

    ludwig Notable Member

    Messages:
    2,253
    Likes Received:
    66
    Best Answers:
    0
    Trophy Points:
    225
    #6
    ludwig, Jul 28, 2008 IP
  7. gray d' newbie

    gray d' newbie Peon

    Messages:
    15
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Thank you in advance ludwig. I will look into that. :)
     
    gray d' newbie, Jul 29, 2008 IP
  8. gray d' newbie

    gray d' newbie Peon

    Messages:
    15
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Thank you very much ludwig. I actually read through the file manipulation before in some of the ASP Tutorial in W3School, but I still didn't find what I'm looking for. From the tutorial I learn how to write into a folder and how to remove them, but I need the function in between which is the PRINTING part so that the sequence goes: WRITE > PRINT > DELETE.

    Thank you very much for your guidance.
     
    gray d' newbie, Jul 29, 2008 IP
  9. ludwig

    ludwig Notable Member

    Messages:
    2,253
    Likes Received:
    66
    Best Answers:
    0
    Trophy Points:
    225
    #9
    for printing you cannot do with asp, the printer is locally on a computer, asp works server side. you might need to use other things, or get asp to make 1 file out of all and then manually print it
     
    ludwig, Jul 30, 2008 IP
  10. gray d' newbie

    gray d' newbie Peon

    Messages:
    15
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Hi ludwig,

    I've actually developed a VBA to handle the printing but again it throw me back some error. It is a long story but I try to keep it simple. First let me show you how the code looks like.

    TargetFolder = "C:\printdocs\"
    Set objShell = CreateObject("Shell.Application")
    Set objFolder = objShell.Namespace(TargetFolder)
    Set colItems = objFolder.Items
    For Each objItem in colItems
    objItem.InvokeVerbEx("Print")
    Next

    This code look sweet in VBA and I tested it, it actually runs seamlessly provided the target folder is in my local desktop. My VBA is actually placed in the server folder and I need to created, print, and remove the files in the server project folder. But if i change my target folder to the folder that placed in the server. It return error as Object variable or With block variable not set pointing on this line: Set colItems = objFolder.Items. I have trying my best to debug this but still no go. Hence I apply the code as VBScript directly in my ASP page and try again.

    When the code applied in ASP directly as VBScript, it returns another error saying that Microsoft VBScript runtime error '800a01a8': Object required: 'objFolder', again pointing at the line: Set colItems = objFolder.Items. Do you have any idea what I've missed in the code?

    Thank you very much

    Best Regards
    Gray d' Newbie
     
    gray d' newbie, Jul 30, 2008 IP
  11. ludwig

    ludwig Notable Member

    Messages:
    2,253
    Likes Received:
    66
    Best Answers:
    0
    Trophy Points:
    225
    #11
    do you DIM, SET your variables before starting to use them?
     
    ludwig, Aug 1, 2008 IP
  12. gray d' newbie

    gray d' newbie Peon

    Messages:
    15
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #12
    Hi ludwig, I understand your concern about variable declaration, me myself is concerning on that as well. To be frank, I got this code from another forum, and I'm so amaze that how come this chunk of code can work without having TargetFolder, objShell, objFolder, colItems, and objItems to be dim at the first place. But they are working fine so I didn't really declare them, and I'm quite confuse how the system can recognize them without having me to dim them.

    P.S. You may try to put this chunk of code into your VB6 and compile it. Trust me, it runs.

    Thank you very much

    Best Regards,
    Gray d' Newbie
     
    gray d' newbie, Aug 3, 2008 IP