How to write binary data

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Swan
    New Member
    • Mar 2008
    • 27

    How to write binary data

    Hi,I am sending binary data from VB to ASP through HttpSendRequest API.I am getting size of file on ASP(using Request.TotalBy tes),which I am sending.Now I want to write it on specific path on server.I tried BinaryRead n BinaryWrite method in ASP,but unable to write.Should I use Binary access method,or anything else?plz suggest me.

    I am posting what I have done:
    Code:
     Dim BinRead 
    	Dim BinWrite
    	BinRead=Request.BinaryRead(Request.TotalBytes)
    BinWrite=Request.BinaryWrite(BinRead)
    I am not getting what BinWrite should return(It's content of file or anything else?).
    Last edited by DrBunchman; Apr 11 '08, 01:34 PM. Reason: Added code tags - note the # button
  • jhardman
    Recognized Expert Specialist
    • Jan 2007
    • 3405

    #2
    I've had this problem before, and I got around it by converting the binary code to ascii characters and saved it with a text stream. Check out this article. If you have any trouble converting this code (which I tested with gifs, jpegs, and Microsoft xls files) give me a holler. Let me know if this helps.

    Jared

    Comment

    • Swan
      New Member
      • Mar 2008
      • 27

      #3
      Originally posted by jhardman
      I've had this problem before, and I got around it by converting the binary code to ascii characters and saved it with a text stream. Check out this article. If you have any trouble converting this code (which I tested with gifs, jpegs, and Microsoft xls files) give me a holler. Let me know if this helps.

      Jared

      Thanks for replying.I tried ADODB.Stream n it worked.There is no need to convert in ASCII code.

      Comment

      • jhardman
        Recognized Expert Specialist
        • Jan 2007
        • 3405

        #4
        Originally posted by Swan
        Thanks for replying.I tried ADODB.Stream n it worked.There is no need to convert in ASCII code.
        Glad you got it to work. I tried ADODB.Stream and couldn't get it to work, even though I knew it should. Care to share your code?

        Jared

        Comment

        • Swan
          New Member
          • Mar 2008
          • 27

          #5
          Originally posted by jhardman
          Glad you got it to work. I tried ADODB.Stream and couldn't get it to work, even though I knew it should. Care to share your code?

          Jared
          I am posting my code for reference:
          Code:
             
          dim myStream,vntPostedData
          vntPostedData = Request.BinaryRead(Request.TotalBytes)
           
          	Set myStream = CreateObject("ADODB.Stream")
          	myStream.Open
          	myStream.Type = 1 ' binary
          	myStream.Write(vntPostedData)		
          	myStream.SaveToFile("C:\testdata.txt")		 
          	myStream.Close
          Last edited by DrBunchman; Apr 22 '08, 12:10 PM. Reason: Added code tags - note the # button

          Comment

          Working...