ASP Code
  Home arrow ASP Code arrow Page 4 - Getting Remote Files With ASP Continued
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Actuate Whitepapers 
Moblin 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP CODE

Getting Remote Files With ASP Continued
By: Justin Cook
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 150
    2005-08-16

    Table of Contents:
  • Getting Remote Files With ASP Continued
  • Let’s Code
  • PerformUpdate() Explained
  • ProcessFile() Explained
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Getting Remote Files With ASP Continued - ProcessFile() Explained


    (Page 4 of 5 )

    The ProcessFile() subroutine appends both the PATH and TRANSFERFILE (the encoded file itself) data to the XML message.

    When adding the TRANSFERFILE node, .txt and .asp files are simply read as text files using FSO and appended to the XML as basic string nodes. If you have any other files that should be read as text (html files, js files, css files, vbs files, and so on), simply add their extension to the ‘if ( InStr(sPath,’ line. Binary files, however, need to be opened using ADO’s Stream object. Then the file is encoded as a Base64 text string, specified as such in the XML node, then appended to the document. This is accomplished with a free xmlDOMDocument object that Microsoft provides. Thanks Microsoft!!!

    If you uncomment the following two debug lines client script (last article):

    'Response.Write sResponse

    'Response.End

    the browser will print out the Base64 encoded text for you when you run the client script in your browser. You’ll notice it looks just like a big square of numbers and letters. The client receives this, and based on the filename in the PATH node, it knows if it’s a normal text file or a binary file. If it’s binary, the client reads the XML as Base64 and uses the ADO object to render the encoded file back into its raw binary form, as we saw in the first article.

    When the binary file is read into memory using the ADO stream object, it is at that point that the dataType property is set to "bin.base64".

    Here’s the code for the subroutine:

    Sub ProcessFile(sPath)

          Dim oRoot, oElement, fFile, tsTextStream

         

          Const ForReading = 1, TristateFalse = 0

          Set oRoot = xmlDOMDocument.documentElement

         

          Set oElement = xmlDOMDocument.createElement("PATH")        

          oElement.nodeTypedValue = sPath

          oRoot.appendChild oElement

          'Here comes the Binary data part

          Set oElement = xmlDOMDocument.createElement("TRANSFERFILE")

          If ( InStr(sPath, ".asp") <= 0 ) And ( InStr(sPath, ".txt") <= 0 ) Then

                objStream.Type = 1      'adTypeBinary

                objStream.Open

                objStream.LoadFromFile(sPath)

               

                oElement.dataType = "bin.base64"

                oElement.nodeTypedValue = objStream.Read

               

                objStream.Close

          Else

                ‘  just read it as a plain text file

                Set fFile = fsoFileObject.GetFile(sPath)

                Set tsTextStream = fFile.OpenAsTextStream(ForReading, TristateFalse)

                oElement.nodeTypedValue = tsTextStream.ReadAll

                tsTextStream.Close

          End If

          ‘ add it to the XML document

          oRoot.appendChild oElement

    End Sub

    More ASP Code Articles
    More By Justin Cook


       · Hi, this is just a note to all readers: hope you enjoy my article!
       · I need to be able to browse images at the computer and uplodade to the web page, can...
       · no, i would just use ASPupload for that
       · I love the article and it was very informing. Is there a way to accomplish the same...
     

    ASP CODE ARTICLES

    - ASP Forms
    - ASP: The Beginning
    - Getting Remote Files With ASP Continued
    - Inbox and Outbox Manipulation in ASP
    - Relational DropDownList Using VB.NET
    - Ad Tracking URL Hits
    - Use ViewState to display one record per page...
    - Send Email using ASP.NET formatted in HTML
    - ASP File Explorer
    - ASP/XML Interview questions by Srivatsan Sri...
    - Various methods of setting Date values to a ...
    - Conditional DataGrid Item and using checkbox...
    - Fill .NET Listbox with SQL DataReader
    - Filling Dropdown box using Code-Behinds in C#
    - FLAMES code sample written in .NET What is F...





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway